|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--Election
Implementation for a single election, which is has a string name and a
list of candidates and count of votes for each candidate. As with the
Server
class, there are methods called
by the election server manager (results are sent to the
display
, errors raise
display exceptions
), and
methods called by Worker
threads (results returned normally, errors raise various exceptions).
All nontrivial methods are declared synchronized
to ensure that
the correct concurrency control between multiple threads occurs.
Field Summary | |
java.lang.String |
name
Name of this election |
Method Summary | |
void |
addCandidate(java.lang.String name)
Add a candidate to this election, only called when the election is created, on server startup |
void |
close(ServerDisplay display)
Close this election and display results, error if already closed (only called by election server manager) |
java.util.LinkedList |
getCandidates()
Get a list of the candidates for the election, error if closed (only called by worker threads) |
boolean |
isOpen()
Is this election open? |
int |
numCandidates()
Get the number of candidates in this election |
void |
open(ServerDisplay display)
Reset vote counts and open this election, error if already open (only called by election server manager) |
void |
view(ServerDisplay display)
Display results for this election, error if open (only called by election server manager |
void |
vote(java.lang.String candidate)
Count a vote for this candidate, error if candidate not found or election not open (only called by worker threads) |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public java.lang.String name
Method Detail |
public void addCandidate(java.lang.String name)
public java.util.LinkedList getCandidates() throws ElectionNotOpenException
ElectionNotOpenException
public void open(ServerDisplay display) throws DisplayException
DisplayException
public void close(ServerDisplay display) throws DisplayException
DisplayException
public void view(ServerDisplay display) throws DisplayException
DisplayException
public void vote(java.lang.String candidate) throws UndefinedCandidateException, ElectionNotOpenException
UndefinedCandidateException
ElectionNotOpenException
public int numCandidates()
public boolean isOpen()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |