/** * Checks whether a sent post is the last in the branch. * * @param checkedPost checked post * @return {@code true} if sent post is the last in the branch, * otherwise {@code false} */ public boolean isLastPost(Post checkedPost) { Validate.notNull(checkedPost); return checkedPost.equals(lastPost); }
/** * Get next post to given post in topic. Following basic cases are possible: * <ol> * <li>In case of one post in topic it returns it back (not valid case from * end-user point of view).</li> * <li>In case if we pass post in the middle of the topic it returns next * post.</li> * <li>In case if we pass last post in the topic it returns previous one.</li> * </ol> * Used to find closest post which is good to be displayed after deletion of * post we pass as a parameter. * * @param post post to search next * @return Neighbor post */ public Post getNeighborPost(Post post) { for (int i = posts.size() - 1; i > 0; i--) { if (posts.get(i).equals(post)) { return (i == posts.size() - 1) ? posts.get(i - 1) : posts .get(i + 1); } } return getFirstPost(); }
/** * Adds new vote to the post or overrides existent * * @param vote vote to add or override */ public void putVote(PostVote vote) { vote.setPost(this); for (PostVote storedVote : votes) { if (storedVote.getUser().equals(vote.getUser()) && storedVote.getPost().equals(vote.getPost())) { storedVote.setVotedUp(vote.isVotedUp()); storedVote.setVoteDate(vote.getVoteDate()); return; } } votes.add(vote); }