001package 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. 002 003import java.util.*; 004import votorola.a.trust.*; 005 006 007/** A context for restricting the casting of votes. 008 */ 009public final class VoteCastingContext 010{ 011 012 013 /** Constructs a VoteCastingContext. 014 * 015 * @throws IllegalStateException if isRealCount is true and voterTraceNode is null 016 */ 017 VoteCastingContext( boolean _isRealCount, TraceNodeW _voterTraceNode, 018 Set<String> _voterDivisions ) 019 { 020 if( _isRealCount && _voterTraceNode == null || _voterDivisions == null ) throw new IllegalStateException( "null registration data for a real count" ); 021 022 isRealCount = _isRealCount; 023 voterTraceNode = _voterTraceNode; 024 voterDivisions = _voterDivisions; 025 } 026 027 028 029 // ------------------------------------------------------------------------------------ 030 031 032 /** Describes the bar against the voter, if any has been set. The description is 033 * intended for users to read. It should include details that may be of help in 034 * overcoming the bar. For instance, if the voter is barred because of insufficient 035 * trust, then the bar should state the required level of trust and how to obtain it. 036 * 037 * @return description of bar, or null if no bar is set. 038 * 039 * @see #setBar(String) 040 * @see CountNodeW#getBar() 041 */ 042 public String getBar() { return bar; } 043 044 045 private String bar; 046 047 048 /** Sets a bar against the voter. 049 * 050 * @see #getBar() 051 */ 052 public void setBar( String newBar ) { bar = newBar; } 053 054 055 056 /** Answers whether eligibility is being determined for the purpose of a real poll 057 * count, or merely in order to echo a change in the voter interface. 058 * 059 * @return true if eligibility is being determined for the purpose of 060 * a real poll count. 061 */ 062 public boolean isRealCount() { return isRealCount; } 063 064 065 private final boolean isRealCount; 066 067 068 069 /** The set of divisions of which the voter is a registered member, as determined from 070 * the latest trace of the trust network, if any. A null value indicates that no 071 * trace is mounted, or the voter was unregistered at mount time. [FIX per 072 * voterTraceNode().] A null value will never occur for a {@linkplain #isRealCount() 073 * real count}. 074 * 075 * @return unmodifiable set of zero or more wiki pagenames and/or URLs; or null 076 * if no trace is mounted. 077 * 078 * @see Registration#divisions() 079 */ 080 public Set<String> voterDivisions() { return voterDivisions; } 081 082 083 private final Set<String> voterDivisions; 084 085 086 087 /** The voter's node from the latest trace of the trust network, if any. A null value 088 * indicates that no trace is mounted, or the voter was unregistered at mount time. 089 * [FIX, so that client can discriminate between the these states. Can use 090 * TraceNodeIC for this.] A null value will never occur for a {@linkplain 091 * #isRealCount() real count}. 092 * 093 * @return voter's trace node, or null if no trace is mounted. 094 */ 095 public TraceNode voterTraceNode() { return voterTraceNode; } 096 097 098 private final TraceNodeW voterTraceNode; 099 100 101}