/** * Determines if user can vote for the post in specified direction. * If direction is true possibility to vote up will be checked. * If direction if false possibility to vote down will be checked. * * @param user user to check * @param direction direction of vote * * @return true if user can vote in specified direction otherwise false */ public boolean canBeVotedBy(JCUser user, boolean direction) { return direction ? !isVotedUpBy(user) : !isVotedDownBy(user); }
/** * Calculates changes in rating of the posh which will be made by specified vote * * @param vote vote for calculating changes; * * @return 0 if user can't vote in direction specified by vote * +/- 1 if user votes first time in up/down direction * +/- 2 if user changes his vote from negative to positive/from positive to negative */ public int calculateRatingChanges(PostVote vote) { if (canBeVotedBy(vote.getUser(), vote.isVotedUp())) { if (isVotedDownBy(vote.getUser())) { return 2; } else if (isVotedUpBy(vote.getUser())) { return -2; } else { return vote.isVotedUp() ? 1 : -1; } } return 0; }