|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.rit.survey.SurveyState
public class SurveyState
Class SurveyState encapsulates the state of a survey. The survey state consists of the name; the question; four answers; and the number of votes for each answer.
The survey state's name, question, and answers cannot be changed once constructed. Survey state objects are compared for equality based on the name, question, and answers.
To deal with the lack of a central server in an ad hoc collaborative application, the survey state object keeps track of each participant's vote individually using an instance of class SurveyVote. Each participant is identified by a unique Eoid, which maps to the participant's vote. A timestamp (logical clock value) is associated with each vote as well. The merge() operation combines two survey state objects, retaining the highest-timestamped vote for each participant.
Field Summary | |
---|---|
static int |
NUM_ANSWERS
The number of answers to a survey question (4). |
Constructor Summary | |
---|---|
SurveyState()
Construct a new empty survey state object. |
|
SurveyState(String theName,
String theQuestion,
String[] theAnswer)
Construct a new survey state object. |
Method Summary | |
---|---|
boolean |
equals(Object obj)
Determine if this survey state is equal to the given object. |
String |
getAnswer(int i)
Get one of this survey state's answers. |
String |
getName()
Get this survey state's name. |
String |
getQuestion()
Get this survey state's question. |
SurveyVote |
getSurveyVote(Eoid id)
Get the survey vote object for the given participant ID in this survey state object. |
int |
getVoteCount(int i)
Get one of this survey state's vote counts. |
int |
hashCode()
Returns a hash code for this survey state. |
void |
merge(SurveyState theSurveyState)
Merge the given survey state object into this survey state object. |
void |
readExternal(ObjectInput in)
Read this survey state from the given object input stream. |
void |
recalculate()
Recalculate the vote counts in this survey state object. |
void |
setSurveyVote(Eoid id,
SurveyVote theSurveyVote)
Set the survey vote object for the given participant ID in this survey state object. |
String |
toString()
Returns a string version of this survey state. |
void |
writeExternal(ObjectOutput out)
Write this survey state to the given object output stream. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int NUM_ANSWERS
Constructor Detail |
---|
public SurveyState()
public SurveyState(String theName, String theQuestion, String[] theAnswer)
theName
- Survey name.theQuestion
- Survey question.theAnswer
- Array of survey answers.
NullPointerException
- (unchecked exception) Thrown if theName,
theQuestion, theAnswer, or any element of
theAnswer is null.
IllegalArgumentException
- (unchecked exception) Thrown if theAnswer does not have the
correct number of elements.Method Detail |
---|
public String getName()
public String getQuestion()
public String getAnswer(int i)
i
- Answer index (0-3).
public int getVoteCount(int i)
i
- Answer index (0-3).
public SurveyVote getSurveyVote(Eoid id)
id
- Participant ID.
public void setSurveyVote(Eoid id, SurveyVote theSurveyVote)
id
- Participant ID.theSurveyVote
- Survey vote object.
NullPointerException
- (unchecked exception) Thrown if theSurveyVote is null.public void recalculate()
public void merge(SurveyState theSurveyState)
theSurveyState
- Survey state object to merge.public void writeExternal(ObjectOutput out) throws IOException
writeExternal
in interface Externalizable
out
- Object output stream.
IOException
- Thrown if an I/O error occurred.public void readExternal(ObjectInput in) throws IOException
readExternal
in interface Externalizable
in
- Object input stream.
IOException
- Thrown if an I/O error occurred.public boolean equals(Object obj)
equals
in class Object
obj
- Object to test.
public int hashCode()
hashCode
in class Object
public String toString()
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |