package votorola.a.election; // Copyright 2008, Michael Allan. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Votorola Software"), to deal in the Votorola Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Votorola Software, and to permit persons to whom the Votorola Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Votorola Software. THE VOTOROLA SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE VOTOROLA SOFTWARE OR THE USE OR OTHER DEALINGS IN THE VOTOROLA SOFTWARE. import votorola.a.register.*; /** A script context for testing the eligibility of a particular vote. */ public class EligibilityContext { /** Constructs a EligibilityContext. * * @param isRealCount per {@linkplain #isRealCount() isRealCount}() * @param listNode per {@linkplain #listNode() listNode}() * @param registration per {@linkplain #registration() registration}() * * @throws IllegalStateException if isRealCount is true, and listNode is null; * or if listNode is non-null, and specifies a list bar */ EligibilityContext( boolean isRealCount, Registration registration, ListNodeC listNode ) { this.isRealCount = isRealCount; this.listNode = listNode; this.registration = registration; if( isRealCount && listNode == null ) throw new IllegalStateException( "null listNode for a real count" ); if( listNode != null && listNode.getBar() != null ) throw new IllegalStateException( "test for vote bar, when voter is list-barred" ); } // ------------------------------------------------------------------------------------ /** Answers whether eligibility is being determined for the purpose of * a real election count, or merely in order to echo a change in the voter interface. * * @return true if eligibility is being determined for the purpose of * a real election count */ public boolean isRealCount() { return isRealCount; } private final boolean isRealCount; /** The voter's node from the latest compilation of the voter list, if any. A null * value indicates that no compiled list is currently available, or the voter was * unregistered when it was compiled. [FIX, so that client can discriminate between * the these states. Can use ListNodeIC for this.] A null value will never occur * for a {@linkplain #isRealCount() real count}. *

* If the listNode is non-null, then it is guaranteed that is does not specify * a {@linkplain ListNode#getBar() list bar}. A list-barred voter * is always ineligible to vote, and never has an eligibility context. *

* * @return voter's list node, or null if there is none */ public ListNode listNode() { return listNode; } private final ListNodeC listNode; /** The voter's current input to the electoral register. */ public Registration registration() { return registration; } private final Registration registration; }