package votorola.a.count; // Copyright 2008-2010, 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 java.util.*; import votorola.a.trust.*; /** A context for restricting the casting of votes. */ public final class VoteCastingContext { /** Constructs a VoteCastingContext. * * @throws IllegalStateException if isRealCount is true and voterTraceNode is null */ VoteCastingContext( boolean _isRealCount, TraceNodeW _voterTraceNode, Set _voterDivisions ) { if( _isRealCount && _voterTraceNode == null || _voterDivisions == null ) throw new IllegalStateException( "null registration data for a real count" ); isRealCount = _isRealCount; voterTraceNode = _voterTraceNode; voterDivisions = _voterDivisions; } // ------------------------------------------------------------------------------------ /** Describes the bar against the voter, if any has been set. The description is * intended for users to read. It should include details that may be of help in * overcoming the bar. For instance, if the voter is barred because of insufficient * trust, then the bar should state the required level of trust and how to obtain it. * * @return description of bar, or null if no bar is set. * * @see #setBar(String) * @see CountNodeW#getBar() */ public String getBar() { return bar; } private String bar; /** Sets a bar against the voter. * * @see #getBar() */ public void setBar( String newBar ) { bar = newBar; } /** Answers whether eligibility is being determined for the purpose of a real poll * 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 poll count. */ public boolean isRealCount() { return isRealCount; } private final boolean isRealCount; /** The set of divisions of which the voter is a registered member, as determined from * the latest trace of the trust network, if any. A null value indicates that no * trace is mounted, or the voter was unregistered at mount time. [FIX per * voterTraceNode().] A null value will never occur for a {@linkplain #isRealCount() * real count}. * * @return unmodifiable set of zero or more wiki pagenames and/or URLs; or null * if no trace is mounted. * * @see Registration#divisions() */ public Set voterDivisions() { return voterDivisions; } private final Set voterDivisions; /** The voter's node from the latest trace of the trust network, if any. A null value * indicates that no trace is mounted, or the voter was unregistered at mount time. * [FIX, so that client can discriminate between the these states. Can use * TraceNodeIC for this.] A null value will never occur for a {@linkplain * #isRealCount() real count}. * * @return voter's trace node, or null if no trace is mounted. */ public TraceNode voterTraceNode() { return voterTraceNode; } private final TraceNodeW voterTraceNode; }