Ejemplo n.º 1
0
  /**
   * Returns first post that is newer then give time
   *
   * @param time time to looking for newer post
   * @return first post that is newer then give time or first post if there is no post that is newer
   */
  private Post getFirstNewerPost(DateTime time) {
    for (Post post : getPosts()) {
      if (post.getCreationDate().isAfter(time)) {
        return post;
      }
    }

    return getFirstPost();
  }
Ejemplo n.º 2
0
 /** Get the date of the last modification of posts in the current topic. */
 public DateTime getLastModificationPostDate() {
   DateTime newTopicModificationDate = getFirstPost().getLastTouchedDate();
   for (Post post : posts) {
     if (post.getLastTouchedDate().isAfter(newTopicModificationDate.toInstant())) {
       newTopicModificationDate = post.getLastTouchedDate();
     }
   }
   return newTopicModificationDate;
 }
Ejemplo n.º 3
0
 /**
  * Calculates modification date of topic taking it as last post in topic creation date. Used after
  * deletion of the post. It is necessary to save the sort order of topics in the future.
  */
 public void recalculateModificationDate() {
   DateTime newTopicModificationDate = getFirstPost().getCreationDate();
   for (Post post : posts) {
     if (post.getCreationDate().isAfter(newTopicModificationDate.toInstant())) {
       newTopicModificationDate = post.getCreationDate();
     }
   }
   modificationDate = newTopicModificationDate;
 }
Ejemplo n.º 4
0
 /** @return content of the first post of the topic */
 public String getBodyText() {
   Post firstPost = getFirstPost();
   return firstPost.getPostContent();
 }
Ejemplo n.º 5
0
 /**
  * Add new {@link Post} to the topic. The method sets Posts.topic field to this Topic.
  *
  * @param post post to add
  */
 public void addPost(Post post) {
   post.setTopic(this);
   updateModificationDate();
   this.posts.add(post);
 }