1 | package nl.rickvanderzwet.toos.assignment1;
|
---|
2 |
|
---|
3 | import java.util.Calendar;
|
---|
4 | import java.util.HashSet;
|
---|
5 | import java.util.Enumeration;
|
---|
6 |
|
---|
7 | import nl.rickvanderzwet.toos.assignment1.Voter;
|
---|
8 |
|
---|
9 | import org.apache.log4j.BasicConfigurator;
|
---|
10 | import org.apache.log4j.Logger;
|
---|
11 |
|
---|
12 | public 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 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 | */
|
---|
24 | public Boolean census(HashSet<Voter> voters) {
|
---|
25 | logger.debug("Starting new comparison");
|
---|
26 |
|
---|
27 | /* Nobody likes voting on Tuesday don't they? */
|
---|
28 | Calendar rightNow = Calendar.getInstance();
|
---|
29 | if (rightNow.get(Calendar.DAY_OF_WEEK) == Calendar.WEDNESDAY) {
|
---|
30 | logger.debug("Sorry not today");
|
---|
31 | return false;
|
---|
32 | }
|
---|
33 |
|
---|
34 | /* No voters return error as result cannot be conclusive */
|
---|
35 | if (voters == null) {
|
---|
36 | return null;
|
---|
37 | }
|
---|
38 |
|
---|
39 | /* Check all votes to make it a fair voting system */
|
---|
40 | for (Voter v: voters) {
|
---|
41 | /* Some vote is not set correctly or of wrong return value */
|
---|
42 | if (v == null || v.getVote() == null || (!(v.getVote() instanceof Boolean))) {
|
---|
43 | return null;
|
---|
44 | }
|
---|
45 |
|
---|
46 | logger.debug(v.getVote());
|
---|
47 | /* All has to be in agreement */
|
---|
48 | if (v.getVote() == false) {
|
---|
49 | return false;
|
---|
50 | }
|
---|
51 | }
|
---|
52 |
|
---|
53 | return true;
|
---|
54 | }
|
---|
55 | }
|
---|
56 |
|
---|