Package berlin.yuna.survey.model.types
Class QuestionGeneric<T,C extends QuestionGeneric<T,C>>
java.lang.Object
berlin.yuna.survey.model.types.QuestionGeneric<T,C>
- All Implemented Interfaces:
Comparable<QuestionGeneric<?,?>>
- Direct Known Subclasses:
Question
,QuestionBool
,QuestionInt
,QuestionList
,QuestionLong
public abstract class QuestionGeneric<T,C extends QuestionGeneric<T,C>> extends Object implements Comparable<QuestionGeneric<?,?>>
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
QuestionGeneric.AnswerRoute<T>
-
Constructor Summary
Constructors Modifier Constructor Description protected
QuestionGeneric(String label)
-
Method Summary
Modifier and Type Method Description Optional<QuestionGeneric<?,?>>
answer()
Answers the question withnull
and returns next questionOptional<QuestionGeneric<?,?>>
answer(T answer)
Returns nextQuestionGeneric
which is configured fot theanswer
attarget(QuestionGeneric)
(Object)}static void
clearAll()
Removes all of the configured mappingsint
compareTo(QuestionGeneric o)
boolean
containsTarget(QuestionGeneric<?,?> question)
Checks if a question is linked in the question flowstatic boolean
containsTarget(QuestionGeneric<?,?> flowStart, QuestionGeneric<?,?> question)
Checks if a question is linked in the question flowboolean
equals(Object o)
static boolean
exists(Enum<?>... label)
static boolean
exists(String... label)
static QuestionGeneric<?,?>
get(Enum<?> label)
Returns the specifiedQuestionGeneric
which is the specified by this labelstatic QuestionGeneric<?,?>
get(String label)
Returns the specifiedQuestionGeneric
which is the specified by this labelstatic QuestionGeneric<?,?>
getOrElse(String label, QuestionGeneric<?,?> fallback)
Returns the specifiedQuestionGeneric
which is the specified by this labelprotected static <K> K
getOrNew(String label, Class<K> type, Supplier<K> instance)
Set<QuestionGeneric<?,?>>
getParentsOf(QuestionGeneric<?,?> question)
Returns a set of parentQuestionGeneric
static Set<QuestionGeneric<?,?>>
getParentsOf(QuestionGeneric<?,?> flowStart, QuestionGeneric<?,?> question)
Returns a set of parentQuestionGeneric
int
hashCode()
String
label()
boolean
match(SurveyAnswer answer)
boolean
onBack(Object answer)
Triggers the on back function which is configured atonBack(Consumer)
C
onBack(Consumer<T> onBack)
Defines what happens when a back transition is requestedabstract Optional<T>
parse(Object answer)
Converts input to the answer type foranswer(Object)
Its also used withinparseAndAnswer(Object)
Optional<QuestionGeneric<?,?>>
parseAndAnswer(Object answer)
Converts input and returns nextQuestionGeneric
which is configured fot theanswer
attarget(QuestionGeneric)
(Object)}Set<QuestionGeneric.AnswerRoute<T>>
routes()
Set<QuestionGeneric<?,?>>
target()
Returns aSet
with all configured targetsC
target(QuestionGeneric<?,?> target)
C
target(QuestionGeneric<?,?> target, Choice<T> condition)
Defines the nexttarget
QuestionGeneric
which will come after callinganswer()
oranswer(Object)
when thecondition
is givenC
target(QuestionGeneric<?,?> target, Function<T,Boolean> condition)
Defines the nexttarget
QuestionGeneric
which will come after callinganswer()
oranswer(Object)
when thecondition
is given<I extends QuestionGeneric<?, ?>>
ItargetGet(I target)
<I extends QuestionGeneric<?, ?>>
ItargetGet(I target, Choice<T> condition)
<I extends QuestionGeneric<?, ?>>
ItargetGet(I target, Function<T,Boolean> condition)
String
toString()
-
Constructor Details
-
QuestionGeneric
-
-
Method Details
-
get
Returns the specifiedQuestionGeneric
which is the specified by this label- Parameters:
label
- The label which is configured for the specifiedlabel
- Returns:
QuestionGeneric
found by thelabel
ornull
if there is no configuration for it
-
get
Returns the specifiedQuestionGeneric
which is the specified by this label- Parameters:
label
- The label which is configured for the specifiedlabel
- Returns:
QuestionGeneric
found by thelabel
ornull
if there is no configuration for it
-
getOrElse
Returns the specifiedQuestionGeneric
which is the specified by this label- Parameters:
label
- The label which is configured for the specifiedlabel
fallback
- if no question was foundlabel
- Returns:
QuestionGeneric
found by thelabel
ornull
if there is no configuration for it
-
clearAll
public static void clearAll()Removes all of the configured mappings -
exists
- Parameters:
label
- label to check for- Returns:
true
if there is a configuration for the specifiedlabel
QuestionGeneric
exists
-
containsTarget
Checks if a question is linked in the question flow- Parameters:
question
-QuestionGeneric
to check if its contained in the flow- Returns:
- true if the
question
is linked in currentQuestionGeneric
flow
-
containsTarget
public static boolean containsTarget(QuestionGeneric<?,?> flowStart, QuestionGeneric<?,?> question)Checks if a question is linked in the question flow- Parameters:
flowStart
-QuestionGeneric
of the flow startquestion
-QuestionGeneric
to check if its contained in the flow- Returns:
- true if the
question
is linked inflowStart
-
getParentsOf
Returns a set of parentQuestionGeneric
- Parameters:
question
-QuestionGeneric
to find the parent of in the flow- Returns:
- a set of parents - set will be empty if no parent was found
-
getParentsOf
public static Set<QuestionGeneric<?,?>> getParentsOf(QuestionGeneric<?,?> flowStart, QuestionGeneric<?,?> question)Returns a set of parentQuestionGeneric
- Parameters:
flowStart
-QuestionGeneric
of the flow startquestion
-QuestionGeneric
to find the parent of in the flow- Returns:
- a set of parents - set will be empty if no parent was found
-
exists
- Parameters:
label
- label to check for- Returns:
true
if there is a configuration for the specifiedlabel
QuestionGeneric
exists
-
target
- Parameters:
target
- defines thetarget
which comes after answering- Returns:
- returns the current object
-
target
Defines the nexttarget
QuestionGeneric
which will come after callinganswer()
oranswer(Object)
when thecondition
is given- Parameters:
target
- defines thetarget
which comes after answeringcondition
-condition
which mussed be true to route to the specifiedtarget
. Can be null if no condition needs to be matched seetarget()
- Returns:
- returns the current object
-
target
Defines the nexttarget
QuestionGeneric
which will come after callinganswer()
oranswer(Object)
when thecondition
is given- Parameters:
target
- defines thetarget
which comes after answeringcondition
-condition
which mussed be true to route to the specifiedtarget
. Can be null if no condition needs to be matched seetarget()
- Returns:
- returns the current object
-
targetGet
- Parameters:
target
- defines thetarget
which comes after answering- Returns:
- returns the
target
object
-
targetGet
- Parameters:
target
- defines thetarget
which comes after answeringcondition
-condition
which mussed be true to route to the specifiedtarget
. Can be null if no condition needs to be matched seetarget()
- Returns:
- returns the
target
object
-
targetGet
- Parameters:
target
- defines thetarget
which comes after answeringcondition
-condition
which mussed be true to route to the specifiedtarget
. Can be null if no condition needs to be matched seetarget()
- Returns:
- returns the
target
object
-
target
Returns aSet
with all configured targets- Returns:
- a set view of all configured
targets
for thisQuestionGeneric
object
-
answer
Answers the question withnull
and returns next question- Returns:
- empty if there is no next question configured
-
parse
Converts input to the answer type foranswer(Object)
Its also used withinparseAndAnswer(Object)
- Parameters:
answer
- input parameter to be parsedtarget(QuestionGeneric)
(Object)}- Returns:
- depends on the implementation - null usually means its not parsable which needs to be cached at
-
parseAndAnswer
Converts input and returns nextQuestionGeneric
which is configured fot theanswer
attarget(QuestionGeneric)
(Object)}- Parameters:
answer
- input parameter- Returns:
Optional.empty()
when question doesn't match configuration - seetarget(QuestionGeneric)
(Object)}
-
answer
Returns nextQuestionGeneric
which is configured fot theanswer
attarget(QuestionGeneric)
(Object)}- Parameters:
answer
- input parameter- Returns:
- returns next
QuestionGeneric
which is configured attarget(QuestionGeneric)
(Object)}
-
label
- Returns:
- label
-
match
- Parameters:
answer
- input for check- Returns:
true
ifSurveyAnswer
relates to the currentQuestionGeneric
-
onBack
Triggers the on back function which is configured atonBack(Consumer)
- Parameters:
answer
- input for on back checks- Returns:
true
on default orfalse
when configured atonBack(Consumer)
-
onBack
Defines what happens when a back transition is requested- Parameters:
onBack
- function which decides what happens when back transition is triggered seeonBack(Object)
- Returns:
- returns the current object
-
routes
-
getOrNew
-
equals
-
hashCode
public int hashCode() -
toString
-
compareTo
- Specified by:
compareTo
in interfaceComparable<T>
-