package nl.rickvanderzwet.toos.assignment1; import java.util.Calendar; import java.util.HashSet; import java.util.Enumeration; import nl.rickvanderzwet.toos.assignment1.Voter; import org.apache.log4j.BasicConfigurator; import org.apache.log4j.Logger; public class Census { static Logger logger = Logger.getLogger(Census.class); public static void main(String[] args) { BasicConfigurator.configure(); Census census = new Census(); HashSet voters = new HashSet(); voters.add(new Voter(true)); voters.add(new Voter(true)); Voter duplicate = new Voter(true); voters.add(duplicate); voters.add(duplicate); //voters.add(new Voter()); logger.info(census.census(voters)); } /** * Calculates the end-vote for a list of voters, given a certain set of creteria's: * - No voter is allowed more than one time on the list. * - All voters present needed to have a vote set. * - Voter.getVote() : Boolean * * @return boolean with conjuction of voters or null on error. */ public Boolean census(HashSet voters) { /* Nobody likes voting on Tuesday don't they? */ Calendar rightNow = Calendar.getInstance(); if (rightNow.get(Calendar.DAY_OF_WEEK) == Calendar.TUESDAY) { return false; } /* Check all votes to make it a fair voting system */ for (Voter v: voters) { logger.debug(v.getVote()); /* Some vote is not set correctly or of wrong return value */ if (v.getVote() == null || (!(v.getVote() instanceof Boolean))) { return false; } /* All has to be in agreement */ if (v.getVote() == false) { return false; } } return true; } }