title: implementing method getMessages java
body: <p>I have a question, I am implementing an application and I want my method getMessages of class user, return me
  A list of all unread messages by the user.</p>
  
  <p>When the user has read the message, it will mark it as read using the read method of the Message class.</p>
  
  <p>The USER class is like this</p>
  
  <pre><code> import java.util.ArrayList;
   import java.util.List;
  
  public class User implements CompetitionListener {
  private Platform platform;
  private String username;
  private String password;
  private String fullName;
  private List&lt;Message&gt; inbox;
  private List&lt;Message&gt; outbox;
  private List&lt;Submission&gt; submissions;
  
  public User (Platform platform, String username, String password, String fullName) {
      /**
       * PR1 Ex 2.1: User constructor needed for user registration
      */
      this.platform = platform;
      this.username = username;
      this.password = password;
      this.fullName = fullName;
      this.inbox = new ArrayList&lt;Message&gt;();
      this.outbox = new ArrayList&lt;Message&gt;();
      this.submissions = new ArrayList&lt;Submission&gt;();
  }
  
  public User (User obj) {
      /**
       * PR1 Ex 2.3: Implementation of the copy constructor
      */
      this.platform = obj.platform;
      this.username = obj.username;
      this.password = obj.password;
      this.fullName = obj.fullName;
      this.inbox = obj.inbox;
      this.outbox = obj.outbox;
      this.submissions = obj.submissions;
  }
  
  public Boolean checkPassword(String password) {   
      /**
       * PR1 Ex 2.2: Implementation of checkPassword, required by login
      */
      return this.password.equals(password);        
  }
  
  public Organizer asOrganizer() {   
      /**
       * PR1 Ex 2.3: Create a new object for the Organizer Role
      */
      return new Organizer(this);
  }
  
  public Participant asParticipant() {
      /**
       * PR1 Ex 2.3: Create a new object for the Participant Role
      */
      return new Participant(this);
  }
  
  public String getUserName() {
      /**
       * PR1 Ex 2.1: Required by method findUser
      */
      return this.username;
  }
  
  public String getFullName() {
      /**
       * PR1 Ex 2.1: Required by test
      */
      return this.fullName;
  }
  
  public String toString() {        
  StringBuilder sb = new StringBuilder ();
  sb.append(getFullName()).append("&lt;").append(getUserName()).append("&gt;");     
      return sb.toString();
     }
  
  public boolean equals(Object obj) {
      /**
       * PR1 Ex 2.2: Required by test
      */
      if(obj==null) {
          return false;
      }        
      if (obj instanceof User) {
          User user = (User) obj;
          if (!this.username.equals(user.username) || !this.password.equals(user.password) || !this.fullName.equals(user.fullName)) {
              return false;
          }        
          // Additional checks can be added
      } else {
          return false;
      }
  
      return true;
     }
  
  public List&lt;Message&gt; getMessages() {        
      return null;
     }
  
  public Message sendMessage(String to, String subject, String message) throws CompetitionException
  { 
  
  User receiver = platform.findUser(to);
  if (to == null) {
      throw new CompetitionException(CompetitionException.RECIPIENT_NOT_FOUND);
  }
  else if(receiver == null ) {
      throw new CompetitionException(CompetitionException.RECIPIENT_NOT_FOUND); //Aquí debes lanza el tipo de excepción apropiado de tu lógica de negocio
  }
  Message m = new Message(this, this, subject, message);
  return m;
  }
  
  public List&lt;Competition&gt; myCompetitions() {
      return null;
  }
  </code></pre>
  
  <p>The MESSAGE class</p>
  
  <pre><code>  import java.text.DateFormat;
   import java.util.Date;
   import java.text.SimpleDateFormat;
  
   public class Message {
  
  private String subject;
  private String message;
  private MessageStatus status;
  private Date createdAt;
  private User to;
  private User from;
  
  public Message (User from, User to, String subject, String message) {
      this.to = to;
      this.from = from;
      this.subject = subject;
      this.message = message; 
      this.createdAt = new Date();
  }
  
  public String getSubject() {
      return subject;
  }
  
  
  public void setSubject(String subject) {
      this.subject = subject;
  }
  
      public String getMessage () {
      return message;
  }
  
  
  public void setMessage(String message) {
      this.message = message;
  }
  
  public void read() {
  
  }
  
  public MessageStatus getStatus() {    
      status = MessageStatus.PENDING;
      return this.status;
  }
  public void setStatus(MessageStatus r) {
      this.status = r;
  }
  
  public Date getCreatedAt() {
      return createdAt;
  }
  
  public String toString() {                    
      StringBuilder sb = new StringBuilder(); 
      SimpleDateFormat sdf=new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); 
      sb.append("{").append("date:").append("&lt;").append(sdf.format(createdAt)).append("&gt;,") 
          .append("from:").append("&lt;").append(from).append(",").append("to:").append("&lt;").append(to).append(",Subject:&lt;").append(subject).append("&gt;,status:&lt;").append(getStatus()).append("&gt;}");//append(price).append("}");
  
      return sb.toString();
  }
  
  public boolean equals(Object obj) { 
     if(obj==null) {
          return false;
      }        
      if (obj instanceof Message) {
          Message message = (Message) obj;
          if (!this.from.equals(message.from) || !this.to.equals(message.to) || !this.status.equals(message.status)|| !this.message.equals(message.message)|| !this.subject.equals(message.subject)) 
  
          {
              return false;
          }        
          // Additional checks can be added
      } else {
          return false;
      }
  
      return true;
  }  
  
  
   }
  
  
  
  
  public List&lt;Message&gt; getInbox() {        
      return this.inbox;
  }
  
  public List&lt;Message&gt; getOutbox() {        
      return this.outbox;
  }    
  
  public Platform getPlatform() {        
      return this.platform;
  }
  
  public void onNewEvaluation() {
  
  }
  public void onCompetitionClosed() {
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I do not know how to implement the getMessages method of the USER class and the read of the Message class.</p>