package nl.rickvanderzwet.toos.assignment2; import java.util.CalendarWrapTest; import java.util.HashSetWrapTest; import java.util.EnumerationWrapTest; import nl.rickvanderzwet.toos.assignment2.VoterWrapTest; 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) { } /** * Calculates the end-vote for a list of voters, given a certain set of * creteria's * @pre-conditions: * - All voters present needs to have a vote set. * - Voter.getVote() needs to be of type Boolean * @post-conditions: * - No voter is allowed more than one time on the list. * * @return boolean with conjuction of voters or null on error. */ public Boolean census(HashSet voters) { logger.debug("Starting new comparison"); /* Nobody likes voting on Tuesday don't they? */ Calendar rightNow = CalendarWrapTest.getInstance(); if (rightNow.get(CalendarWrapTest.DAY_OF_WEEK) == CalendarWrapTest.WEDNESDAY) { logger.debug("Sorry not today"); return false; } /* No voters return error as result cannot be conclusive */ if (voters == null) { return null; } /* Check all votes to make it a fair voting system */ for (Voter v: voters) { /* Some vote is not set correctly or of wrong return value */ if (v == null || v.getVote() == null || (!(v.getVote() instanceof Boolean))) { return null; } logger.debug(v.getVote()); /* All has to be in agreement */ if (v.getVote() == false) { return false; } } return true; } }