source: liacs/TOOS2010/assignment2/src/Census.java@ 250

Last change on this file since 250 was 237, checked in by Rick van der Zwet, 14 years ago

Improvement to include a JavaDoc comment.

File size: 1.6 KB
RevLine 
[205]1package nl.rickvanderzwet.toos.assignment1;
2
[206]3import java.util.Calendar;
[205]4import java.util.HashSet;
[206]5import java.util.Enumeration;
6
[205]7import nl.rickvanderzwet.toos.assignment1.Voter;
[206]8
[205]9import org.apache.log4j.BasicConfigurator;
10import org.apache.log4j.Logger;
11
[204]12public class Census {
[205]13 static Logger logger = Logger.getLogger(Census.class);
[204]14 public static void main(String[] args) {
15 }
[206]16 /**
[237]17 * Calculates the end-vote for a list of voters, given a certain set of
18 * creteria's
19 * @pre-conditions:
20 * - All voters present needs to have a vote set.
21 * - Voter.getVote() needs to be of type Boolean
22 * @post-conditions:
[206]23 * - No voter is allowed more than one time on the list.
24 *
25 * @return boolean with conjuction of voters or null on error.
26 */
[210]27 public Boolean census(HashSet<Voter> voters) {
28 logger.debug("Starting new comparison");
[209]29
[206]30 /* Nobody likes voting on Tuesday don't they? */
31 Calendar rightNow = Calendar.getInstance();
[209]32 if (rightNow.get(Calendar.DAY_OF_WEEK) == Calendar.WEDNESDAY) {
[210]33 logger.debug("Sorry not today");
[206]34 return false;
35 }
36
[210]37 /* No voters return error as result cannot be conclusive */
38 if (voters == null) {
39 return null;
40 }
41
[206]42 /* Check all votes to make it a fair voting system */
43 for (Voter v: voters) {
44 /* Some vote is not set correctly or of wrong return value */
[210]45 if (v == null || v.getVote() == null || (!(v.getVote() instanceof Boolean))) {
[209]46 return null;
[206]47 }
48
[210]49 logger.debug(v.getVote());
[206]50 /* All has to be in agreement */
51 if (v.getVote() == false) {
52 return false;
53 }
54 }
55
56 return true;
[205]57 }
[204]58}
59
Note: See TracBrowser for help on using the repository browser.