[205] | 1 | package nl.rickvanderzwet.toos.assignment1;
|
---|
| 2 |
|
---|
[206] | 3 | import java.util.Calendar;
|
---|
[205] | 4 | import java.util.HashSet;
|
---|
[206] | 5 | import java.util.Enumeration;
|
---|
| 6 |
|
---|
[205] | 7 | import nl.rickvanderzwet.toos.assignment1.Voter;
|
---|
[206] | 8 |
|
---|
[205] | 9 | import org.apache.log4j.BasicConfigurator;
|
---|
| 10 | import org.apache.log4j.Logger;
|
---|
| 11 |
|
---|
[204] | 12 | public class Census {
|
---|
[205] | 13 | static Logger logger = Logger.getLogger(Census.class);
|
---|
[204] | 14 | public static void main(String[] args) {
|
---|
[205] | 15 | BasicConfigurator.configure();
|
---|
[206] | 16 |
|
---|
| 17 | Census census = new Census();
|
---|
| 18 |
|
---|
[205] | 19 | HashSet<Voter> voters = new HashSet<Voter>();
|
---|
| 20 | voters.add(new Voter(true));
|
---|
[206] | 21 | voters.add(new Voter(true));
|
---|
| 22 | Voter duplicate = new Voter(true);
|
---|
| 23 | voters.add(duplicate);
|
---|
| 24 | voters.add(duplicate);
|
---|
| 25 | //voters.add(new Voter());
|
---|
| 26 |
|
---|
| 27 | logger.info(census.census(voters));
|
---|
[204] | 28 | }
|
---|
[206] | 29 | /**
|
---|
| 30 | * Calculates the end-vote for a list of voters, given a certain set of creteria's:
|
---|
| 31 | * - No voter is allowed more than one time on the list.
|
---|
| 32 | * - All voters present needed to have a vote set.
|
---|
| 33 | * - Voter.getVote() : Boolean
|
---|
| 34 | *
|
---|
| 35 | * @return boolean with conjuction of voters or null on error.
|
---|
| 36 | */
|
---|
| 37 | public Boolean census(HashSet<Voter> voters) {
|
---|
| 38 | /* Nobody likes voting on Tuesday don't they? */
|
---|
| 39 | Calendar rightNow = Calendar.getInstance();
|
---|
| 40 | if (rightNow.get(Calendar.DAY_OF_WEEK) == Calendar.TUESDAY) {
|
---|
| 41 | return false;
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | /* Check all votes to make it a fair voting system */
|
---|
| 45 | for (Voter v: voters) {
|
---|
| 46 | logger.debug(v.getVote());
|
---|
| 47 | /* Some vote is not set correctly or of wrong return value */
|
---|
| 48 | if (v.getVote() == null || (!(v.getVote() instanceof Boolean))) {
|
---|
| 49 | return false;
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | /* All has to be in agreement */
|
---|
| 53 | if (v.getVote() == false) {
|
---|
| 54 | return false;
|
---|
| 55 | }
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | return true;
|
---|
[205] | 59 | }
|
---|
[204] | 60 | }
|
---|
| 61 |
|
---|