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
Modifier and TypeClassDescriptionstatic final class
Records a user's response to a question. -
Constructor Summary
ConstructorDescriptionAnswer
(@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.Response
static 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 boolean
boolean
getId()
The question that was answered<T> T
getValueAs
(Class<T> asClass) <T> List<T>
getValuesAs
(Class<T> asClass) Returns the bound value(s) for this answer as the given class.int
hashCode()
static Answer
boolean
isEmpty()
boolean
isSameQuestion
(Question rhsQuestion) Returns true if this answer was given for the given question and question setstatic Answer
Useful testing constructor for assembling a single response answerstatic Answer
static Answer
Useful testing constructor for creating answers for tests where the bound type is a string as well.nz.org.riskscape.engine.bind.Parameter
toString()
-
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.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
- Returns:
- a copy of the complete list of
Answer.Response
s 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
-