org.bolson.vote
Class Histogram

java.lang.Object
  extended by org.bolson.vote.VotingSystem
      extended by org.bolson.vote.Histogram
All Implemented Interfaces:
java.io.Serializable

public class Histogram
extends VotingSystem

Collects votes and presents HTML histograms.

See Also:
Serialized Form

Field Summary
 java.lang.String barImgUrl
          URL to insert in generated Histogram HTML.
static java.lang.String defaultValueTitle
           
 boolean useSpan
           
 java.lang.String valueTitle
           
 
Fields inherited from class org.bolson.vote.VotingSystem
debug, NO_VOTE, numc
 
Constructor Summary
Histogram(int numc)
           
Histogram(int numcIn, int nbuck, double min, double max)
           
 
Method Summary
 void addRanking(int[] rankings)
           
 void addRating(double[] ratings)
           
 void addRating(float[] ratings)
           
 void addRating(int[] ratings)
           
 void clear()
           
 int[] getWinners()
          Do processing if necessary, return winners.
 int[] getWinners(int numSeats)
          Do processing if necessary, return winners.
 java.lang.String htmlSummary(java.lang.String[] names)
          A fancy html representation.
 VotingSystem init(java.lang.String[] argv)
          Arguments to modify behavior of VotingSystem
 java.lang.String toString()
           
 java.lang.String toString(int style, java.lang.String[] names)
           
 java.lang.String toString(java.lang.String[] names)
          A more interesting representation.
 int voteRanking(int[] rankings)
           
 int voteRating(double[] ratings)
           
 int voteRating(float[] ratings)
           
 int voteRating(int[] ratings)
           
 
Methods inherited from class org.bolson.vote.VotingSystem
checkRatedVote, getDebugHTML, getDebugText, getNumberOfCandidates, getWinners, getWinners, isValidRankedVote, isValidRatedVote, name, normalize, normalize, normalize, normalize, normalize, normalizeL2, normalizeL2, normalizeL2, normalizeL2, normalizeL2, stretch, voteRating
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

barImgUrl

public java.lang.String barImgUrl
URL to insert in generated Histogram HTML. Defaults to relative URL "b.png" .


useSpan

public boolean useSpan

defaultValueTitle

public static java.lang.String defaultValueTitle

valueTitle

public java.lang.String valueTitle
Constructor Detail

Histogram

public Histogram(int numcIn,
                 int nbuck,
                 double min,
                 double max)

Histogram

public Histogram(int numc)
Method Detail

init

public VotingSystem init(java.lang.String[] argv)
Description copied from class: VotingSystem
Arguments to modify behavior of VotingSystem

Overrides:
init in class VotingSystem
Returns:
this so that you can do
vs = (new VS(numc)).init( new String[]{"blah", "grunt"} );

clear

public void clear()

voteRanking

public int voteRanking(int[] rankings)
Specified by:
voteRanking in class VotingSystem
Parameters:
rankings - An array int[N]. ranking[i] is the ranking of choice i. rankings are 1 (most preferred) through N (least). INT_MAX, N, or NO_VOTE for unspecified.
Returns:
0 on success

addRanking

public void addRanking(int[] rankings)

voteRating

public int voteRating(int[] ratings)
Specified by:
voteRating in class VotingSystem
Parameters:
ratings - An array int[numc]. rating[i] is the rating of choice i. A rating can be any int value. Higher means more preferred. NO_VOTE for unrated.
Returns:
0 on success

addRating

public void addRating(int[] ratings)

voteRating

public int voteRating(float[] ratings)
Specified by:
voteRating in class VotingSystem
Parameters:
ratings - An array int[N]. rating[i] is the rating of choice i. A rating can be any int value. Higher means more preferred. NO_VOTE for unrated.
Returns:
0 on success

addRating

public void addRating(float[] ratings)

voteRating

public int voteRating(double[] ratings)
Specified by:
voteRating in class VotingSystem
Parameters:
ratings - An array int[N]. rating[i] is the rating of choice i. A rating can be any int value. Higher means more preferred. NO_VOTE for unrated.
Returns:
0 on success

addRating

public void addRating(double[] ratings)

toString

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

toString

public java.lang.String toString(int style,
                                 java.lang.String[] names)

htmlSummary

public java.lang.String htmlSummary(java.lang.String[] names)
Description copied from class: VotingSystem
A fancy html representation. Include the names of the choices voted upon in the representation.

Specified by:
htmlSummary in class VotingSystem
Parameters:
names - The names of the choices. May be null.
Returns:
state, with names!

toString

public java.lang.String toString(java.lang.String[] names)
Description copied from class: VotingSystem
A more interesting representation. Include the names of the choices voted upon in the representation.

Specified by:
toString in class VotingSystem
Parameters:
names - The names of the choices.
Returns:
state, with names!

getWinners

public int[] getWinners()
Description copied from class: VotingSystem
Do processing if necessary, return winners.

It is recommended to cache the return value in such a way that calling this function again does not do complex recalculation. That cache should be cleared if voteRating or voteRanking is called.

Specified by:
getWinners in class VotingSystem
Returns:
indecies of winners (hopefully 1 of them)

getWinners

public int[] getWinners(int numSeats)
Description copied from class: VotingSystem
Do processing if necessary, return winners. Default implementation returns null so that not all systems have to be multi-seat systems.

It is recommended to cache the return value in such a way that calling this function again does not do complex recalculation. That cache should be cleared if voteRating or voteRanking is called.

Overrides:
getWinners in class VotingSystem
Parameters:
numSeats - the number of seats available.
Returns:
indecies of winners, hopefully numSeats of them but in case of ties there may be more and in case of some internal schism there may be fewer. Check .length to be sure.