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

Last change on this file since 369 was 310, checked in by Rick van der Zwet, 13 years ago

Hacking with javascript and various other foo.

File size: 1.7 KB
RevLine 
[310]1package nl.rickvanderzwet.toos.assignment2;
[205]2
[310]3import java.util.CalendarWrapTest;
4import java.util.HashSetWrapTest;
5import java.util.EnumerationWrapTest;
[206]6
[310]7import nl.rickvanderzwet.toos.assignment2.VoterWrapTest;
[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? */
[310]31 Calendar rightNow = CalendarWrapTest.getInstance();
32 if (rightNow.get(CalendarWrapTest.DAY_OF_WEEK) == CalendarWrapTest.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.