|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.bolson.vote.NameVotingSystem
public abstract class NameVotingSystem
Taking a bunch of (name,rating) pairs this type of voting system allows for write-ins and perhaps a somewhat simpler usage.
Nested Class Summary | |
---|---|
static class |
NameVotingSystem.NameVote
|
static class |
NameVotingSystem.ReverseComparator
|
Constructor Summary | |
---|---|
NameVotingSystem()
|
Method Summary | |
---|---|
void |
defaultMain(java.lang.String[] argv)
Use this for making simple subclass main() to run a vote of that type. |
static int |
denibble(char c)
|
static java.lang.String |
depercentHexify(java.lang.String in)
un-escape ASCII string with %xx escapes in it to, converting such sequences to bytes. |
static NameVotingSystem.NameVote[] |
fromUrlEncoded(java.lang.String s)
Parse a name=value&name=value url query type string into a NameVote[]. |
java.lang.String |
getDebug()
If debug, return debugLog.toString(), else null. |
static java.util.Iterator |
getImplNames()
|
static java.lang.Class |
getIpmlForName(java.lang.String name)
|
abstract NameVotingSystem.NameVote[] |
getWinners()
|
java.lang.String |
htmlExplain()
Get HTML explaination of how the election worked. |
java.lang.StringBuffer |
htmlExplain(java.lang.StringBuffer sb)
Get HTML explaination of how the election worked. |
java.lang.String |
htmlSummary()
Get HTML summary of voting system state. |
abstract java.lang.StringBuffer |
htmlSummary(java.lang.StringBuffer sb)
Get HTML summary of voting system state. |
int |
init(java.lang.String[] argv)
Set options for voting system. |
abstract java.lang.String |
name()
|
static NameVotingSystem.NameVote[] |
nameEqStrToVoteArray(java.lang.String cd)
Convert Name=Rating pairs in a string to an array of NameVote. |
static NameVotingSystem.NameVote[] |
nameEqStrToVoteArray(java.lang.String cd,
java.lang.String splitPattern,
boolean trimWhitespace)
Convert Name=Rating pairs in a string to an array of NameVote. |
static java.lang.String |
percentHexify(java.lang.String s)
It's just like return s.replaceAll( "%", "%25" ).replaceAll( "&", "%26" ).replaceAll( "=", "%3d" ); but faster. |
void |
readVotes(java.io.Reader r)
Reads tab separated name=rating vote per line. |
protected static void |
registerImpl(java.lang.String name,
java.lang.Class c)
|
static void |
resultsHTMLDisplay(java.io.PrintWriter out,
NameVotingSystem[] vs,
boolean debug,
int numSeats)
Print full results. |
static void |
sort(NameVotingSystem.NameVote[] they)
|
static java.lang.String |
urlEncode(NameVotingSystem.NameVote[] they)
url encode a vote |
void |
voteNameEqStr(java.lang.String cd)
Vote a tab-separated name=rating string. |
void |
voteOrderSpec(java.lang.String vote)
Vote an ordering specified by a string. |
void |
voteRating(java.util.Map vote)
Vote a set of ratings. |
abstract void |
voteRating(NameVotingSystem.NameVote[] vote)
Vote a set of ratings. |
static NameVotingSystem.NameVote[] |
voteSpecToNameVoteArray(java.lang.String cd)
Convert a list of names separated by '>' or '='. |
static void |
winnerSummaryHTMLTable(java.io.PrintWriter out,
NameVotingSystem[] vs,
boolean debug,
int numSeats)
Print summary table. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public NameVotingSystem()
Method Detail |
---|
public java.lang.String getDebug()
public int init(java.lang.String[] argv)
argv
- array of options, just like main()
public void voteOrderSpec(java.lang.String vote)
vote
- A String of names separated by '>' or '='.voteRating(NameVote[])
public void voteRating(java.util.Map vote)
vote
- a set of (name,rating) pairsvoteRating(NameVote[])
public abstract void voteRating(NameVotingSystem.NameVote[] vote)
vote
- a set of (name,rating) pairsvoteRating(Map)
public abstract NameVotingSystem.NameVote[] getWinners()
public abstract java.lang.StringBuffer htmlSummary(java.lang.StringBuffer sb)
sb
- a valid StringBuffer to which HTML summary will be appended.
public abstract java.lang.String name()
public java.lang.String htmlSummary()
htmlSummary(StringBuffer)
public java.lang.StringBuffer htmlExplain(java.lang.StringBuffer sb)
htmlSummary(StringBuffer)
.
Can be optionally overrided for extra educational benefit.
It may be really slow.
It may be a complete re-implementation of the election method that emits stuff as it goes.
sb
- a valid StringBuffer to which HTML explaination will be appended.
public java.lang.String htmlExplain()
htmlExplain(StringBuffer)
.
htmlExplain(StringBuffer)
public static NameVotingSystem.NameVote[] voteSpecToNameVoteArray(java.lang.String cd)
cd
- names
public static NameVotingSystem.NameVote[] nameEqStrToVoteArray(java.lang.String cd, java.lang.String splitPattern, boolean trimWhitespace)
cd
- String like "Name One=9 Name Two=3 Name Three=-9"splitPattern
- pattern to break cd ontrimWhitespace
- remove excess whitespace at start and end of names
public static NameVotingSystem.NameVote[] nameEqStrToVoteArray(java.lang.String cd)
cd
- String like "Name One=9 Name Two=3 Name Three=-9"
public void voteNameEqStr(java.lang.String cd)
public static void sort(NameVotingSystem.NameVote[] they)
public void readVotes(java.io.Reader r) throws java.io.IOException
java.io.IOException
public void defaultMain(java.lang.String[] argv)
public static java.lang.String percentHexify(java.lang.String s)
s
- string to %hex escape
public static int denibble(char c) throws java.lang.NumberFormatException
java.lang.NumberFormatException
public static java.lang.String depercentHexify(java.lang.String in)
in
- string which may have %xx escapes in it
public static NameVotingSystem.NameVote[] fromUrlEncoded(java.lang.String s)
s
- the url query type string with candidate names and ratings
public static java.lang.String urlEncode(NameVotingSystem.NameVote[] they)
they
- vote to encode
public static void winnerSummaryHTMLTable(java.io.PrintWriter out, NameVotingSystem[] vs, boolean debug, int numSeats)
out
- receives the html tablevs
- systems that have been voted and can getWinnersdebug
- sets if getWinners is to collect debug infonumSeats
- number of seats available in this electionpublic static void resultsHTMLDisplay(java.io.PrintWriter out, NameVotingSystem[] vs, boolean debug, int numSeats)
out
- receives the html resultsvs
- systems that have been voted and can getWinnersdebug
- sets if getWinners is to collect debug infonumSeats
- number of seats available in this electionprotected static void registerImpl(java.lang.String name, java.lang.Class c)
public static java.lang.Class getIpmlForName(java.lang.String name)
public static java.util.Iterator getImplNames()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |