1 | package nl.rickvanderzwet.toos.assignment2;
|
---|
2 |
|
---|
3 | import java.util.CalendarWrapTest;
|
---|
4 | import java.util.HashSetWrapTest;
|
---|
5 | import java.util.EnumerationWrapTest;
|
---|
6 |
|
---|
7 | import nl.rickvanderzwet.toos.assignment2.VoterWrapTest;
|
---|
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
|
---|
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 = CalendarWrapTest.getInstance();
|
---|
32 | if (rightNow.get(CalendarWrapTest.DAY_OF_WEEK) == CalendarWrapTest.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 |
|
---|