votorola.a.election
Class CountNode

java.lang.Object
  extended by CountNode
All Implemented Interfaces:
Serializable, Cloneable
Direct Known Subclasses:
CountNodeIC

public class CountNode
extends Object
implements Cloneable, Serializable

A node in a delegate cascade, it records the cumulative cast/count state for a single voter/candidate. It is partly serializeable; when unserialized, it becomes detached from the table, so that calling any of the table-dependent methods (such as commit, or trace) will result in a runtime exception.

See Also:
Serialized Form

Nested Class Summary
static class CountNode.Table
          The relational store of count nodes that (in part) backs a election count.
 
Constructor Summary
CountNode(CountNode.Table table, String voterEmail)
          Creates a CountNode with default values: all counts at zero, no chosen candidate, and no vote cast.
CountNode(CountNode.Table table, String voterEmail, String bar, String candidateEmail, long carryCount, boolean isCast, long rank, long rankIndex, long receiveCount)
          Constructs a CountNode.
 
Method Summary
 long carryCount()
          The number of received votes that are carried to the candidate node along with this node's single cast vote.
(package private)  CountNode[] cast(boolean toCarry)
          Attempts to cast a vote for the chosen candidate.
 CountNode clone()
           
(package private)  void commit()
          Writes this node to the table, if it has uncommitted changes.
 String getBar()
          The bar against the voter, if any.
 String getCandidateEmail()
          Identifies the candidate for whom the voter will be voting, once the vote is actually cast.
 long getRank()
          Returns the rank assigned to this node, with respect to votes received.
 long getRankIndex()
          Returns the unique index assigned to this node, by order of rank, and (secondarily) email address.
 long holdCount()
          The number of votes held.
 boolean isCast()
          Returns true if a vote was successfully cast for the candidate; false otherwise.
 long receiveCount()
          The number of votes received from other nodes.
(package private)  void setBar(String newBar)
          Sets an eligibility bar against the voter.
(package private)  void setCandidateEmail(String newCandidateEmail)
          Changes the candidate for whom the voter will be voting.
(package private)  void setRank(long newRank)
          Assigns a rank to this node.
(package private)  void setRankIndex(long newRankIndex)
          Assigns a rank index to this node.
 long singleCastCount()
          The number of votes cast for the candidate; either 0 or 1.
 CountNode.Table table()
          The table in which this node is stored.
 String toString()
          Returns the voter email address.
(package private)  CountNode[] trace()
          Traces the route a vote would follow if it a cast were attempted from this node to the candidate node, and carried onward to the terminal node.
(package private)  CountNode[] uncast(boolean toCarry)
          Withdraws a vote for the candidate, if one was cast.
 String voterEmail()
          Identifies the voter.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CountNode

CountNode(CountNode.Table table,
          String voterEmail)
Creates a CountNode with default values: all counts at zero, no chosen candidate, and no vote cast.

Parameters:
table - per table()
voterEmail - per voterEmail()

CountNode

CountNode(CountNode.Table table,
          String voterEmail,
          String bar,
          String candidateEmail,
          long carryCount,
          boolean isCast,
          long rank,
          long rankIndex,
          long receiveCount)
Constructs a CountNode.

Parameters:
table - per table()
voterEmail - per voterEmail()
bar - per getBar()
candidateEmail - per getCandidateEmail()
carryCount - per carryCount()
isCast - per isCast()
receiveCount - per receiveCount()
Method Detail

carryCount

public final long carryCount()
The number of received votes that are carried to the candidate node along with this node's single cast vote. The single cast vote is excluded from this count.

See Also:
holdCount()

commit

final void commit()
           throws SQLException
Writes this node to the table, if it has uncommitted changes.

Throws:
SQLException

holdCount

public final long holdCount()
The number of votes held. This is simply receiveCount - carryCount.


getBar

public final String getBar()
The bar against the voter, if any. A barred voter is ineligible to vote in this election. The bar may be either an eligibility bar, or a list bar. An eligibility bar is specific to an election. For example, the voter must reside in the specific district of the election.

The bar may also be a list bar. A list bar applies to all elections.

Returns:
description of bar, or null if there is no bar
See Also:
setBar(String)

setBar

final void setBar(String newBar)
Sets an eligibility bar against the voter.

See Also:
getBar()

getRank

public final long getRank()
Returns the rank assigned to this node, with respect to votes received. The numerical minimum is a rank of 1 (top rank), assigned to the node(s) receiving the most votes. Rank progresses incrementally, with no gaps. All nodes receiving the same number of votes are assigned the same rank.
1, 2, 2, 3, 4, 4, 4, 4, 4, 4, 4

In the example above, two candidates are tied for second place (rank 2). The bottom rank of 4 is shared by 7 voters who are probably non-candidates (receiving no votes).

Returns:
rank of 1 or larger; or 0, if no rank has been assigned, because the count is still in progress
See Also:
setRank(long)

setRank

final void setRank(long newRank)
Assigns a rank to this node.

See Also:
getRank()

getRankIndex

public final long getRankIndex()
Returns the unique index assigned to this node, by order of rank, and (secondarily) email address. This index serves for constructing predictable paged views of the rankings.

Returns:
rank index of 0 or larger
See Also:
setRankIndex(long)

setRankIndex

final void setRankIndex(long newRankIndex)
Assigns a rank index to this node.

See Also:
getRankIndex()

isCast

public final boolean isCast()
Returns true if a vote was successfully cast for the candidate; false otherwise.

See Also:
cast(boolean), uncast(boolean)

cast

final CountNode[] cast(boolean toCarry)
                throws SQLException
Attempts to cast a vote for the chosen candidate. If the voter is barred, the vote will go nowhere. Otherwise, it may cascade, affecting counts on other nodes.

Parameters:
toCarry - Set to true to carry the received votes along with the cast vote. Set to false to transfer the single vote of this voter, alone.
Returns:
trace
Throws:
IllegalStateException - if the vote is already cast,
SQLException
See Also:
uncast(boolean)

uncast

final CountNode[] uncast(boolean toCarry)
                  throws SQLException
Withdraws a vote for the candidate, if one was cast.

Parameters:
toCarry - Set to true to withdraw any carried votes along with the cast vote. Set to false to withdraw the single vote of this voter, alone.
Returns:
trace
Throws:
SQLException
See Also:
cast(boolean)

receiveCount

public final long receiveCount()
The number of votes received from other nodes.

See Also:
carryCount, holdCount()

singleCastCount

public final long singleCastCount()
The number of votes cast for the candidate; either 0 or 1.

See Also:
carryCount(), cast(boolean), isCast()

table

public final CountNode.Table table()
The table in which this node is stored.

Returns:
table, or null if this is a deserialized, read-only node

trace

final CountNode[] trace()
                 throws SQLException
Traces the route a vote would follow if it a cast were attempted from this node to the candidate node, and carried onward to the terminal node.

Returns:
array of nodes from the casting node (index 0) to the terminal node (length-1)
Throws:
SQLException

getCandidateEmail

public final String getCandidateEmail()
Identifies the candidate for whom the voter will be voting, once the vote is actually cast.

Returns:
canonical email address (having no personal part); or null, if the voter has not attempted to cast a vote
See Also:
setCandidateEmail(String)

setCandidateEmail

final void setCandidateEmail(String newCandidateEmail)
Changes the candidate for whom the voter will be voting. In order for the change to affect the election state, you would normally call uncast(true) beforehand, then cast(true) afterwards.

See Also:
getCandidateEmail()

voterEmail

public final String voterEmail()
Identifies the voter.

Returns:
canonical email address (having no personal part)

clone

public final CountNode clone()
Overrides:
clone in class Object

toString

public final String toString()
Returns the voter email address.

Overrides:
toString in class Object