source: liacs/TOOS/assignment1/src/Census.java@ 209

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

Some more usefull tests and debugging

File size: 1.4 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 /**
17 * Calculates the end-vote for a list of voters, given a certain set of creteria's:
18 * - No voter is allowed more than one time on the list.
19 * - All voters present needed to have a vote set.
20 * - Voter.getVote() : Boolean
21 *
22 * @return boolean with conjuction of voters or null on error.
23 */
[209]24 public static Boolean census(HashSet<Voter> voters) {
25
[206]26 /* Nobody likes voting on Tuesday don't they? */
27 Calendar rightNow = Calendar.getInstance();
[209]28 if (rightNow.get(Calendar.DAY_OF_WEEK) == Calendar.WEDNESDAY) {
[206]29 return false;
30 }
31
32 /* Check all votes to make it a fair voting system */
33 for (Voter v: voters) {
34 logger.debug(v.getVote());
35 /* Some vote is not set correctly or of wrong return value */
36 if (v.getVote() == null || (!(v.getVote() instanceof Boolean))) {
[209]37 logger.debug("Invalid type");
38 return null;
[206]39 }
40
41 /* All has to be in agreement */
42 if (v.getVote() == false) {
43 return false;
44 }
45 }
46
47 return true;
[205]48 }
[204]49}
50
Note: See TracBrowser for help on using the repository browser.