edu.indiana.util.statistics
Class RunningVote

java.lang.Object
  extended by edu.indiana.util.statistics.RunningVote
All Implemented Interfaces:
RunningAggregate, java.io.Serializable

public class RunningVote
extends java.lang.Object
implements RunningAggregate

Maintains a running vote among double values. Ties are broken arbitrarily, according to iteration order of the Double objects within a HashMap. This class is particularly useful for tracking an aggregate value for a nominal variable.

See Also:
Serialized Form

Field Summary
protected  java.lang.Double majorityValue
          The value of the current majority.
protected  double majorityVoteCount
          The number of votes the majority value has received.
protected  double totalVoteCount
          The total number of votes being tracked in this RunningVote object.
protected  java.util.HashMap votes
          A mapping from a Double value to the number of votes (a MutableDouble) received for that value so far.
 
Constructor Summary
RunningVote()
           
RunningVote(java.util.HashMap votes)
           
 
Method Summary
 void add(double voteRecipient)
           
 void add(double voteRecipient, double voteAmount)
          Add a vote for the given value.
 double calcAggregateValue()
           
protected  void calcMajority()
           
 boolean equals(java.lang.Object otherObj)
           
 double getAgreeCount()
           
 double getDisagreeCount()
           
 double getMax()
           
 double getMin()
           
 int hashCode()
           
static void main(java.lang.String[] args)
          A simple test method.
 void remove(double votesRemovedFrom)
          Remove a vote for the given value.
 void remove(double votesRemovedFrom, double amountToRemove)
          Remove a vote for the given value.
 void reset()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

votes

protected java.util.HashMap votes
A mapping from a Double value to the number of votes (a MutableDouble) received for that value so far.


majorityValue

protected java.lang.Double majorityValue
The value of the current majority. Also serves as a key into the votes HashMap.


majorityVoteCount

protected double majorityVoteCount
The number of votes the majority value has received.


totalVoteCount

protected double totalVoteCount
The total number of votes being tracked in this RunningVote object.

Constructor Detail

RunningVote

public RunningVote()

RunningVote

public RunningVote(java.util.HashMap votes)
Method Detail

calcMajority

protected void calcMajority()

add

public void add(double voteRecipient)
Specified by:
add in interface RunningAggregate

add

public void add(double voteRecipient,
                double voteAmount)
Add a vote for the given value.


remove

public void remove(double votesRemovedFrom)
Remove a vote for the given value.

Specified by:
remove in interface RunningAggregate

remove

public void remove(double votesRemovedFrom,
                   double amountToRemove)
Remove a vote for the given value.


calcAggregateValue

public double calcAggregateValue()
Specified by:
calcAggregateValue in interface RunningAggregate

getAgreeCount

public double getAgreeCount()

getDisagreeCount

public double getDisagreeCount()

reset

public void reset()
Specified by:
reset in interface RunningAggregate

equals

public boolean equals(java.lang.Object otherObj)
Specified by:
equals in interface RunningAggregate
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Specified by:
hashCode in interface RunningAggregate
Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

main

public static void main(java.lang.String[] args)
A simple test method.


getMax

public double getMax()
Specified by:
getMax in interface RunningAggregate

getMin

public double getMin()
Specified by:
getMin in interface RunningAggregate