Package net.starype.quiz.api.game.answer
Class Answer
- java.lang.Object
-
- net.starype.quiz.api.game.answer.Answer
-
public class Answer extends java.lang.Object
Wrapper for character string answers.
Mainly used to avoid primitive obsession and offer quick conversion methods
-
-
Method Summary
Modifier and Type Method Description double
asDouble()
int
asInt()
boolean
equals(java.lang.Object o)
static Answer
fromString(java.lang.String answer)
Construct an Answer object from the given stringstatic java.util.Set<Answer>
fromStringCollection(java.util.Collection<java.lang.String> stringCollection)
Maps a collection of string to a set of answersjava.lang.String
getAnswerText()
int
hashCode()
java.util.List<Answer>
split(java.lang.String regex)
Split the answer using the given regexjava.lang.String
toString()
-
-
-
Method Detail
-
fromString
public static Answer fromString(java.lang.String answer)
Construct an Answer object from the given string- Parameters:
answer
- the character string corresponding to the answer- Returns:
- the Answer object created
-
fromStringCollection
public static java.util.Set<Answer> fromStringCollection(java.util.Collection<java.lang.String> stringCollection)
Maps a collection of string to a set of answers- Parameters:
stringCollection
- the collection of character strings- Returns:
- the set of answers computed
-
getAnswerText
public java.lang.String getAnswerText()
- Returns:
- the text value of the answer
-
asInt
public int asInt()
- Returns:
- the text value of the answer as an integer
-
asDouble
public double asDouble()
- Returns:
- the text value of the answer as a double
-
split
public java.util.List<Answer> split(java.lang.String regex)
Split the answer using the given regex- Parameters:
regex
- the regex used to split the text value of the answer object- Returns:
- a list containing the result of the split
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-