Class Answer

java.lang.Object
nz.org.riskscape.wizard.Answer

public class Answer extends Object

Records an answer to a question that has been bound to a type according to Question.getParameterType()

Note that an Answer can simply indicate that a Question was presented to the user, even if the user choose to skip it and not give an actual response.

  • Constructor Details

  • Method Details

    • bind

      public static nz.org.riskscape.problem.ResultOrProblems<Answer.Response> bind(nz.org.riskscape.engine.bind.BindingContext context, Question chosen, Object input)

      Convenience method for binding a single input value for the given question in to a single Answer.Response

    • bindAll

      public static nz.org.riskscape.problem.ResultOrProblems<Answer> bindAll(nz.org.riskscape.engine.bind.BindingContext context, Question question, List<?> responses)

      Convenience method for binding a list of responses in to an answer, return a failed result if any of the responses failed to bind.

    • strings

      public static Answer strings(Question answered, String... valuesAndResponses)

      Useful testing constructor for creating answers for tests where the bound type is a string as well.

    • single

      public static Answer single(Question answered, Object boundValue, Object response)

      Useful testing constructor for assembling a single response answer

    • hidden

      public static Answer hidden(Question answered)
      Returns:
      an Answer that is suitable for the given hidden question
    • skip

      public static Answer skip(Question notAnswered)
      Returns:
      an Answer that represents the user skipping the given question
    • getValues

      public List<Object> getValues()
    • getValuesAs

      public <T> List<T> getValuesAs(Class<T> asClass)

      Returns the bound value(s) for this answer as the given class.

    • getValueAs

      public <T> T getValueAs(Class<T> asClass)
      Returns:
      the bound value for the answer as the given class
    • getResponse

      public Answer.Response getResponse()
      Returns:
      the Answer.Response object that stores both the user supplied value and the bound value for this answer, or null if no response was recorded.
      Throws:
      IllegalArgumentException - if the question answered doesn't expect a single response
    • getResponses

      public List<Answer.Response> getResponses()
      Returns:
      a copy of the complete list of Answer.Responses for this answser
    • getOriginalResponses

      public List<Object> getOriginalResponses()
      Returns:
      a copy of the complete list of inputs the user gave as part of this answer
    • isSameQuestion

      public boolean isSameQuestion(Question rhsQuestion)

      Returns true if this answer was given for the given question and question set

    • getId

      public String getId()
      Returns:
      the ID of the Question being answered
    • getQuestionSet

      public QuestionSet getQuestionSet()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toParameter

      public nz.org.riskscape.engine.bind.Parameter toParameter()
    • isEmpty

      public boolean isEmpty()
      Returns:
      true if this answer has no responses recorded, i.e. the Question was skipped.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • canEqual

      protected boolean canEqual(Object other)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getQuestion

      public Question getQuestion()

      The question that was answered