Class Question
A Question to ask the user within a Survey
.
Questions can have a predicate test (i.e. askWhen(Predicate)
associated with them to control whether or not they should be asked.
Questions may be optional or required, and may accept multiple Answers.
Questions can have dependencies (i.e. #dependsOn(String)
, so they
don't get asked until after an earlier Question has been answered.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
The parameter type assigned to all hidden questions.static interface
A functional interface for returning translated strings for a question. -
Field Summary
Modifier and TypeFieldDescriptionstatic final Question.I18nLookupFunction
static final Question.Hidden
The only instance of the hidden value you'll ever need.static final String
Assigned to annotations without values, so that we don't have to deal with nullstatic final com.google.common.collect.Range<Integer>
static final com.google.common.collect.Range<Integer>
static final com.google.common.collect.Range<Integer>
static final com.google.common.collect.Range<Integer>
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionaskWhen
(Predicate<IncrementalBuildState> conditionMet) Adds a predicate condition that should be met before this question is asked.atLocation
(ChangeLocation newChangeLocation) protected boolean
void
checkValidity
(List<Object> values) sanity checking code to prevent an invalid answer being recorded - the errors are not meant for human consumption but we might want to adapt them laterMake a new Question that's dependent on the given questionName being asked first.boolean
static String
formatName
(String name) getAnnotation
(String tag) @NonNull com.google.common.collect.Range<Integer>
getArity()
getAskAs()
@NonNull ChangeLocation
getChoices
(IncrementalBuildState buildState) getCompositeSubparts
(Question question, Class<?> clazz) getDescription
(Locale locale) getId()
Returns a unique ID for the Question (which is dependent on theQuestionSet
it belongs to.getMessage
(String suffix, Locale locale) nz.org.riskscape.engine.i18n.MessageSource
@NonNull String
getName()
@NonNull Class<?>
getPhase()
@NonNull Predicate<IncrementalBuildState>
getSubQuestion
(String fieldName) getSummary
(Locale locale) Returns of concise bit of text that summarizes this question.boolean
hasAnnotation
(String tag) boolean
hasAnnotationWithValue
(String tag, String value) int
hashCode()
hidden()
Constructs a clone of this question, but makes it a hidden question.inSet
(QuestionSet newQuestionSet) boolean
isAskAs()
boolean
static boolean
isComposite
(Class<?> clazz) boolean
isFollowing
(Question question) boolean
isHidden()
boolean
The opposite (negation) of isRequiredboolean
boolean
isRequired
(IncrementalBuildState buildState) Check if the question is really required.boolean
boolean
parseAnnotations
(String... newAnnotationStrings) boolean
readyToBeAsked
(IncrementalBuildState buildState) Checks the dependent questions have already been asked and the question is applicable.void
Explosive method for API users to fail fast if when they do a single value thing on a multi value questionnz.org.riskscape.engine.bind.Parameter
Returns a Parameter representing this question (so that saved wizard answers can be overridden from the CLI).toString()
withAnnotations
(String k1, String v1) withAnnotations
(String k1, String v1, String k2, String v2) <T> Question
withChoices
(Function<IncrementalBuildState, List<Choice>> newFunction) withI18nLookup
(BiFunction<String, Locale, String> newLookup) withI18nLookup
(Question.I18nLookupFunction newLookup) Clone this question, but with a new parameter type field.
-
Field Details
-
HIDDEN_VALUE
The only instance of the hidden value you'll ever need. Should be stored as the bound value in a Response object, with an empty string or empty list as the user's original value (or some other non null and empty value)
-
DEFAULT_I18N_LOOKUP
-
ONE_REQUIRED
-
ONE_AT_LEAST
-
OPTIONAL_ONE
-
OPTIONAL_MANY
-
NO_VALUE
Assigned to annotations without values, so that we don't have to deal with null
- See Also:
-
-
Constructor Details
-
Question
-
-
Method Details
-
isComposite
- Returns:
- true if the given type is for a "composite" question, i.e. a question that is actually split into several composite sub-parts
-
getCompositeSubparts
- Returns:
- a list of the sub-parts to a composite question, or an empty list if given class is is not composite or has no composite fields
-
formatName
- Returns:
- a cleaned up name that is OK to use as a label for this question
-
readyToBeAsked
Checks the dependent questions have already been asked and the question is applicable.
-
isFollowing
- Returns:
- true if this question is dependent on (i.e. follows) the given question.
-
atLeastOne
-
requiredOne
-
optionalOne
-
optionalMany
-
parseAnnotations
- Parameters:
newAnnotationStrings
- a list of annotations to parse, each string can be either a tag (which will be assigned NO_VALUE) or atag=value
string.- Returns:
- a copy of this
Question
but with the given tags replacing whatever was there before.
-
withAnnotations
- Returns:
- a copy of this
Question
but with the given tags replacing whatever was there before
-
withAnnotations
- Returns:
- a copy of this
Question
but with the given tags replacing whatever was there before
-
withAnnotations
- Returns:
- a copy of this
Question
but with the given tags replacing whatever was there before
-
hasAnnotation
- Returns:
- true if there is a tag attached to this
Question
that matches the given string
-
hasAnnotationWithValue
- Returns:
- true if there is a tag attached to this
Question
that matches the tag and it has contains value
-
getAnnotation
-
dependsOn
Make a new Question that's dependent on the given questionName being asked first. Note that these dependencies are only for Questions within the same QuestionSet.
-
withType
Clone this question, but with a new parameter type field.
-
askWhen
Adds a predicate condition that should be met before this question is asked.
-
isSingleValueQuestion
public boolean isSingleValueQuestion()- Returns:
- true if this question wants at most one answer
-
isRequired
public boolean isRequired()- Returns:
- true if at least one response is required for this question
-
isOptional
public boolean isOptional()The opposite (negation) of isRequired
- Returns:
- true if this question is not hidden but can be skipped
-
isHidden
public boolean isHidden()- Returns:
- true if this question should be hidden from the user. See
hidden()
-
isRequired
Check if the question is really required. A question if required if it should be asked, and also requires an answer.
- Returns:
- true if question requires a response
-
checkValidity
sanity checking code to prevent an invalid answer being recorded - the errors are not meant for human consumption but we might want to adapt them later
-
requireSingleValueQuestion
public void requireSingleValueQuestion()Explosive method for API users to fail fast if when they do a single value thing on a multi value question
-
getId
Returns a unique ID for the Question (which is dependent on the
QuestionSet
it belongs to. -
toParameter
public nz.org.riskscape.engine.bind.Parameter toParameter()Returns a Parameter representing this question (so that saved wizard answers can be overridden from the CLI).
-
toString
-
getQuestionSet
- Returns:
- the QuestionSet this question belongs to
- Throws:
IllegalStateException
- if this question is unassigned
-
getPhase
- Returns:
- the phase this question is connected to (via its QuestionSet)
-
isUnassigned
public boolean isUnassigned()- Returns:
- true if the question does not yet belong to a
QuestionSet
. A question can assigned to a set by calling the inSet clone method.
-
inSet
- Returns:
- a clone of this Question but with it assigned to the given question set
-
withName
-
withI18nLookup
-
withI18nLookup
-
atLocation
-
getTitle
-
getDescription
-
getSummary
Returns of concise bit of text that summarizes this question. This is really closer to title, and title should be 'prompt', but to avoid churn, this gets a the new name instead of renaming all the things
-
getMessage
-
getMessageSource
public nz.org.riskscape.engine.i18n.MessageSource getMessageSource() -
getSurvey
-
withChoices
-
getChoices
- Returns:
- A list of Choices that are acceptable, predefined answers for this question
-
isComposite
public boolean isComposite()- Returns:
- true if this is a "composite" question, i.e. a question that is actually split into several composite sub-parts
-
getCompositeSubparts
- Returns:
- a list of the sub-parts to a composite question
-
getDependsOn
-
isAskAs
public boolean isAskAs()- Returns:
- true if this question can be converted to a differently asked question for a customized UI, while recording the result as some other type.
-
withAskAs
-
withAskAs
-
getAskAs
-
getAskedAs
-
getSubQuestion
- Returns:
- the composite sub-question that corresponds to the given fieldName
-
getName
-
getParameterType
-
getShouldBeAsked
-
getArity
-
getAnnotations
-
getI18nLookup
-
getChoiceFunction
-
getChangeLocation
- Returns:
- a ChangeLocation that is associated with this question. The
ChangeLocation
provides an indication to UIs and to Survey code of where the change triggered by a response to this question should be applied. It defaults to 'at the last change', which is what 90% of questions will want to do when incrementally building.
-
equals
-
canEqual
-
hashCode
public int hashCode()
-