Class 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 string
      static java.util.Set<Answer> fromStringCollection​(java.util.Collection<java.lang.String> stringCollection)
      Maps a collection of string to a set of answers
      java.lang.String getAnswerText()  
      int hashCode()  
      java.util.List<Answer> split​(java.lang.String regex)
      Split the answer using the given regex
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • 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 class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object