Package berlin.yuna.survey.model.types
Class FlowItem<T,C extends FlowItem<T,C>>
- java.lang.Object
-
- berlin.yuna.survey.model.types.FlowItem<T,C>
-
- Type Parameters:
T
- Item typeC
- Self item class
- All Implemented Interfaces:
Comparable<FlowItem<?,?>>
- Direct Known Subclasses:
Question
,QuestionBool
,QuestionInt
,QuestionList
,QuestionLong
public abstract class FlowItem<T,C extends FlowItem<T,C>> extends Object implements Comparable<FlowItem<?,?>>
-
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
addParent(FlowItem<?,?> parent)
Optional<FlowItem<?,?>>
answer(T answer)
Returns nextFlowItem
which is configured for a back transitionint
compareTo(FlowItem o)
DiagramExporter
diagram()
Prepares diagram rendererboolean
equals(Object o)
<I extends FlowItem<?,?>>
Optional<I>find(I search)
SearchFlowItem
in current flowOptional<T>
fromJson(String answerJson)
Converts json to answer object<I extends FlowItem<?,?>>
Optional<I>get(I type)
Get a flow item by the givenFlowItem
Optional<FlowItem<?,?>>
get(Enum<?> label)
Get a flow item by the givenenum
Optional<FlowItem<?,?>>
get(String label)
Get a flow item by the givenString
<I extends FlowItem<?,?>>
IgetOrElse(I type, I fallback)
Get a flow item by thistype
FlowItem<?,?>
getOrElse(Enum<?> label, FlowItem<?,?> fallback)
Get a flow item by thisenum
FlowItem<?,?>
getOrElse(String label, FlowItem<?,?> fallback)
Get a flow item by thisString
int
hashCode()
String
label()
boolean
match(HistoryItemBase<?> answer)
C
onBack(Condition<T>... conditions)
Defines a back transition oftargets()
C
onBack(Class<? extends Condition<?>>... conditions)
Defines a back transition target oftargets()
C
onBack(Function<T,Boolean> condition)
Defines a back transition oftargets()
Set<FlowItem<?,?>>
parents()
Returns aSet
with all configured targetsabstract Optional<T>
parse(ContextExchange context)
(Optional) Input converter to handle the answer - used to solveparseAndApply(ContextExchange, Function)
Optional<FlowItem<?,?>>
parseAndAnswer(ContextExchange context)
Returns nextFlowItem
which is configured for a back transitionprotected <R> Optional<R>
parseAndApply(ContextExchange context, Function<T,Optional<R>> function)
Returns nextFlowItem
which is configured for a back transitionOptional<Boolean>
parseAndRevert(ContextExchange context)
Reverts configured actions for a back transitionsOptional<Boolean>
revert(T answer)
Returns nextFlowItem
which is configured for a back transitionSet<Route<T>>
routes()
C
target(FlowItem<?,?> target)
Defines a transition target oftargets()
A previous target without conditions will be overwrittenC
target(FlowItem<?,?> target, Condition<T> condition)
Defines a transition target oftargets()
C
target(FlowItem<?,?> target, Class<? extends Condition<?>> condition)
Defines a transition target oftargets()
C
target(FlowItem<?,?> target, Function<T,Boolean> condition)
Defines a transition target oftargets()
<I extends FlowItem<?,?>>
ItargetGet(I target)
Defines a transition target oftargets()
<I extends FlowItem<?,?>>
ItargetGet(I target, Condition<T> condition)
Defines a transition target oftargets()
<I extends FlowItem<?,?>>
ItargetGet(I target, Function<T,Boolean> condition)
Defines a transition target oftargets()
Set<FlowItem<?,?>>
targets()
Returns aSet
with all configured targetsSet<FlowItem<?,?>>
targetsBack()
Returns aSet
with all configured targetsString
toJson(Object answer)
Converts answer object to jsonString
toString()
TransitionSet<T>
transitions()
-
-
-
Constructor Detail
-
FlowItem
public FlowItem(String label)
-
-
Method Detail
-
get
public Optional<FlowItem<?,?>> get(Enum<?> label)
Get a flow item by the givenenum
- Parameters:
label
- Thelabel
to search in flow- Returns:
Optional
orOptional.empty()
when flow doesn't contain the requested item
-
get
public Optional<FlowItem<?,?>> get(String label)
Get a flow item by the givenString
- Parameters:
label
- Thelabel
to search in flow- Returns:
Optional
orOptional.empty()
when flow doesn't contain the requested item
-
get
public <I extends FlowItem<?,?>> Optional<I> get(I type)
Get a flow item by the givenFlowItem
- Parameters:
type
-FlowItem
to search in flow- Returns:
Optional
orOptional.empty()
when flow doesn't contain the requested item
-
getOrElse
public FlowItem<?,?> getOrElse(String label, FlowItem<?,?> fallback)
Get a flow item by thisString
-
getOrElse
public FlowItem<?,?> getOrElse(Enum<?> label, FlowItem<?,?> fallback)
Get a flow item by thisenum
-
getOrElse
public <I extends FlowItem<?,?>> I getOrElse(I type, I fallback)
Get a flow item by thistype
-
target
public C target(FlowItem<?,?> target)
Defines a transition target oftargets()
A previous target without conditions will be overwritten- Parameters:
target
- defines the transition target- Returns:
- the current object
-
target
public C target(FlowItem<?,?> target, Function<T,Boolean> condition)
Defines a transition target oftargets()
- Parameters:
target
- defines the transition targetcondition
-condition
to match. Ontrue
will execute the transition - Conditions can be also used to trigger a process- Returns:
- current object
-
target
public C target(FlowItem<?,?> target, Condition<T> condition)
Defines a transition target oftargets()
- Parameters:
target
- defines the transition targetcondition
-condition
to match. Ontrue
will execute the transition - Conditions can be also used to trigger a process- Returns:
- current object
-
target
public C target(FlowItem<?,?> target, Class<? extends Condition<?>> condition)
Defines a transition target oftargets()
- Parameters:
target
- defines the transition targetcondition
-condition
to match. Ontrue
will execute the transition - Conditions can be also used to trigger a process- Returns:
- current object
-
targetGet
public <I extends FlowItem<?,?>> I targetGet(I target)
Defines a transition target oftargets()
- Parameters:
target
- defines the transition target- Returns:
target
object
-
targetGet
public <I extends FlowItem<?,?>> I targetGet(I target, Function<T,Boolean> condition)
Defines a transition target oftargets()
- Parameters:
target
- defines the transition targetcondition
-condition
to match. Ontrue
will execute the transition - Conditions can be also used to trigger a process- Returns:
target
object
-
targetGet
public <I extends FlowItem<?,?>> I targetGet(I target, Condition<T> condition)
Defines a transition target oftargets()
- Parameters:
target
- defines the transition targetcondition
-condition
to match. Ontrue
will execute the transition - Conditions can be also used to trigger a process- Returns:
target
object
-
targets
public Set<FlowItem<?,?>> targets()
Returns aSet
with all configured targets- Returns:
- a set view of all configured
targets
for thisFlowItem
object
-
onBack
public C onBack(Function<T,Boolean> condition)
Defines a back transition oftargets()
- Parameters:
condition
-condition
to match. Ontrue
will execute the transition - Conditions can be also used to trigger a process- Returns:
- current object
-
onBack
public C onBack(Condition<T>... conditions)
Defines a back transition oftargets()
- Parameters:
conditions
-condition
to match. Ontrue
will execute the transition - Conditions can be also used to trigger a process- Returns:
- current object
-
onBack
public C onBack(Class<? extends Condition<?>>... conditions)
Defines a back transition target oftargets()
- Parameters:
conditions
-condition
to match. Ontrue
will execute the transition - Conditions can be also used to trigger a process- Returns:
- current object
-
targetsBack
public Set<FlowItem<?,?>> targetsBack()
Returns aSet
with all configured targets- Returns:
- a set view of all configured
targets
for thisFlowItem
object
-
parents
public Set<FlowItem<?,?>> parents()
Returns aSet
with all configured targets- Returns:
- a set view of all configured
targets
for thisFlowItem
object
-
parse
public abstract Optional<T> parse(ContextExchange context)
(Optional) Input converter to handle the answer - used to solveparseAndApply(ContextExchange, Function)
- Parameters:
context
- input parameter to be parsed for the condition of a configuredRoute
- Returns:
Optional.empty()
to used the default cast and JSON parserparseAndApply(ContextExchange, Function)
-
parseAndAnswer
public Optional<FlowItem<?,?>> parseAndAnswer(ContextExchange context)
Returns nextFlowItem
which is configured for a back transition- Parameters:
context
- input parameter- Returns:
- next (
backTransition
)FlowItem
-
parseAndApply
protected <R> Optional<R> parseAndApply(ContextExchange context, Function<T,Optional<R>> function)
Returns nextFlowItem
which is configured for a back transition- Parameters:
context
- input parameterfunction
- apply after parsing- Returns:
- next (
backTransition
)FlowItem
-
toJson
public String toJson(Object answer)
Converts answer object to json- Parameters:
answer
- to convert to json- Returns:
- input as json format
-
fromJson
public Optional<T> fromJson(String answerJson)
Converts json to answer object- Parameters:
answerJson
- json to be converted to object- Returns:
- object from json
-
answer
public Optional<FlowItem<?,?>> answer(T answer)
Returns nextFlowItem
which is configured for a back transition- Parameters:
answer
- input parameter- Returns:
- next (
backTransition
)FlowItem
-
parseAndRevert
public Optional<Boolean> parseAndRevert(ContextExchange context)
Reverts configured actions for a back transitions- Parameters:
context
- input parameter- Returns:
true
if transition is allowed (empty if no transition is configured)
-
revert
public Optional<Boolean> revert(T answer)
Returns nextFlowItem
which is configured for a back transition- Parameters:
answer
- input parameter- Returns:
true
if transition is allowed (empty if no transition is configured)
-
label
public String label()
- Returns:
- label
-
match
public boolean match(HistoryItemBase<?> answer)
- Parameters:
answer
- input for check- Returns:
true
ifHistoryItem
relates to the currentFlowItem
-
transitions
public TransitionSet<T> transitions()
- Returns:
- a copy of configured routes
-
diagram
public DiagramExporter diagram()
Prepares diagram renderer- Returns:
DiagramExporter
renderer
-
find
public <I extends FlowItem<?,?>> Optional<I> find(I search)
SearchFlowItem
in current flow- Parameters:
search
- type to search in flow- Returns:
Optional.empty()
of not found
-
addParent
protected void addParent(FlowItem<?,?> parent)
-
compareTo
public int compareTo(FlowItem o)
- Specified by:
compareTo
in interfaceComparable<T>
-
-