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

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

Improvement to include a JavaDoc comment.

File size: 1.6 KB
Line 
1package nl.rickvanderzwet.toos.assignment1;
2
3import java.util.Calendar;
4import java.util.HashSet;
5import java.util.Enumeration;
6
7import nl.rickvanderzwet.toos.assignment1.Voter;
8
9import org.apache.log4j.BasicConfigurator;
10import org.apache.log4j.Logger;
11
12public class Census {
13 static Logger logger = Logger.getLogger(Census.class);
14 public static void main(String[] args) {
15 }
16 /**
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:
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 */
27 public Boolean census(HashSet<Voter> voters) {
28 logger.debug("Starting new comparison");
29
30 /* Nobody likes voting on Tuesday don't they? */
31 Calendar rightNow = Calendar.getInstance();
32 if (rightNow.get(Calendar.DAY_OF_WEEK) == Calendar.WEDNESDAY) {
33 logger.debug("Sorry not today");
34 return false;
35 }
36
37 /* No voters return error as result cannot be conclusive */
38 if (voters == null) {
39 return null;
40 }
41
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 */
45 if (v == null || v.getVote() == null || (!(v.getVote() instanceof Boolean))) {
46 return null;
47 }
48
49 logger.debug(v.getVote());
50 /* All has to be in agreement */
51 if (v.getVote() == false) {
52 return false;
53 }
54 }
55
56 return true;
57 }
58}
59
Note: See TracBrowser for help on using the repository browser.