Class Answer
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classRecords a user's response to a question. -
Constructor Summary
ConstructorsConstructorDescriptionAnswer(@NonNull Question answered, @NonNull List<Answer.Response> values) Answer(Question answered, Answer.Response... responses) -
Method Summary
Modifier and TypeMethodDescriptionstatic nz.org.riskscape.problem.ResultOrProblems<Answer.Response>Convenience method for binding a single input value for the given question in to a singleAnswer.Responsestatic nz.org.riskscape.problem.ResultOrProblems<Answer>Convenience method for binding a list of responses in to an answer, return a failed result if any of the responses failed to bind.protected booleanbooleangetId()The question that was answered<T> TgetValueAs(Class<T> asClass) <T> List<T>getValuesAs(Class<T> asClass) Returns the bound value(s) for this answer as the given class.inthashCode()static AnswerbooleanisEmpty()booleanisSameQuestion(Question rhsQuestion) Returns true if this answer was given for the given question and question setstatic AnswerUseful testing constructor for assembling a single response answerstatic Answerstatic AnswerUseful testing constructor for creating answers for tests where the bound type is a string as well.nz.org.riskscape.engine.bind.ParametertoString()
-
Constructor Details
-
Answer
-
Answer
-
-
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
Useful testing constructor for creating answers for tests where the bound type is a string as well.
-
single
Useful testing constructor for assembling a single response answer
-
skip
- Returns:
- an Answer that represents the user skipping the given question
-
getValues
-
getValuesAs
Returns the bound value(s) for this answer as the given class.
-
getValueAs
- Returns:
- the bound value for the answer as the given class
-
getResponse
- Returns:
- the
Answer.Responseobject 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
- Returns:
- a copy of the complete list of
Answer.Responses for this answser
-
getOriginalResponses
- Returns:
- a copy of the complete list of inputs the user gave as part of this answer
-
isSameQuestion
Returns true if this answer was given for the given question and question set
-
getId
- Returns:
- the ID of the Question being answered
-
getQuestionSet
-
toString
-
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
-
canEqual
-
hashCode
public int hashCode() -
getQuestion
The question that was answered
-