/** * 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; }
/** * 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(); }