Class Election

java.lang.Object
  |
  +--Election

public class Election
extends java.lang.Object

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

name

public java.lang.String name
Name of this election

Method Detail

addCandidate

public void addCandidate(java.lang.String name)
Add a candidate to this election, only called when the election is created, on server startup


getCandidates

public java.util.LinkedList getCandidates()
                                   throws ElectionNotOpenException
Get a list of the candidates for the election, error if closed (only called by worker threads)

ElectionNotOpenException

open

public void open(ServerDisplay display)
          throws DisplayException
Reset vote counts and open this election, error if already open (only called by election server manager)

DisplayException

close

public void close(ServerDisplay display)
           throws DisplayException
Close this election and display results, error if already closed (only called by election server manager)

DisplayException

view

public void view(ServerDisplay display)
          throws DisplayException
Display results for this election, error if open (only called by election server manager

DisplayException

vote

public void vote(java.lang.String candidate)
          throws UndefinedCandidateException,
                 ElectionNotOpenException
Count a vote for this candidate, error if candidate not found or election not open (only called by worker threads)

UndefinedCandidateException
ElectionNotOpenException

numCandidates

public int numCandidates()
Get the number of candidates in this election


isOpen

public boolean isOpen()
Is this election open?