Package berlin.yuna.survey.logic
Class Survey
- java.lang.Object
-
- berlin.yuna.survey.logic.Survey
-
public class Survey extends Object
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Survey
answer(Object answer)
Solves the currentFlowItem
of the flowSurvey
answer(Object answer, Object context)
Solves the currentFlowItem
of the flowSurvey
autoBackTransition(boolean enableAutomatic)
Defines if back transitions are allowed for non configured back conditionsDiagramExporter
diagram()
Prepares diagram rendererprotected FlowItem<?,?>
findLast(LinkedList<HistoryItem> historySorted)
FlowItem<?,?>
get()
Get currentFlowItem
of the flow<I extends FlowItem<?,?>>
Iget(I type)
Get a flow item by the givenFlowItem
FlowItem<?,?>
get(Enum<?> label)
Get a flow item by the givenenum
To avoid cast its recommended to useFlowItem.get(FlowItem)
FlowItem<?,?>
get(String label)
Get a flow item by the givenString
To avoid cast its recommended to useFlowItem.get(FlowItem)
Map<String,Long>
getDurationsMS()
Returns times taken between each question useful to track answer timesFlowItem<?,?>
getFirst()
Get firstFlowItem
of the flowList<HistoryItem>
getHistory()
Get history of answersList<HistoryItemJson>
getHistoryJson()
Get history of answersint
getHistorySize()
Get history sizeFlowItem<?,?>
getPrevious()
Get previousFlowItem
from the flowboolean
hasAutoBackTransition()
Definition if back transitions are allowed for non configured back conditionsstatic Survey
init(FlowItem<?,?> flowStart)
Starts new SurveyCtxstatic Survey
init(FlowItem<?,?> flowStart, Iterable<? extends HistoryItemBase<?>> history)
boolean
isEnded()
Check if the current flow has endedboolean
transitTo(FlowItem<?,?> target)
Transit to a specificFlowItem
in the flowboolean
transitTo(FlowItem<?,?> target, Object context)
Transit to a specificFlowItem
in the flowboolean
transitTo(String label)
Transit to a specificFlowItem
in the flowboolean
transitTo(String label, Object context)
Transit to a specificFlowItem
in the flow
-
-
-
Method Detail
-
init
public static Survey init(FlowItem<?,?> flowStart)
Starts new SurveyCtx- Parameters:
flowStart
- start item of the flow- Returns:
Survey
- Throws:
IllegalStateException
- onnull
-
init
public static Survey init(FlowItem<?,?> flowStart, Iterable<? extends HistoryItemBase<?>> history)
- Parameters:
flowStart
- start item of the flowhistory
- should not be empty asSurvey
needs a start item- Returns:
Survey
- Throws:
IllegalStateException
- when thehistory
is empty or has no validFlowItem
-
transitTo
public boolean transitTo(String label)
Transit to a specificFlowItem
in the flow- Parameters:
label
- forFlowItem
to transition to- Returns:
true
if transition is allowed,false
on back transition config- Throws:
IllegalArgumentException
- if the label is not part of the flow or when the forward transition has not enough answers
-
transitTo
public boolean transitTo(String label, Object context)
Transit to a specificFlowItem
in the flow- Parameters:
label
- forFlowItem
to transition tocontext
- sets the context onContextExchange
which is used atFlowItem.parse(ContextExchange)
- Returns:
true
if transition is allowed,false
on back transition config- Throws:
IllegalArgumentException
- if the label is not part of the flow or when the forward transition has not enough answers
-
transitTo
public boolean transitTo(FlowItem<?,?> target)
Transit to a specificFlowItem
in the flow- Parameters:
target
-FlowItem
to transition to- Returns:
true
if transition is allowed,false
on config ofFlowItem.onBack(Condition[])
- Throws:
IllegalArgumentException
- if the label is not part of the flow or when the forward transition has not enough answers (will transition to the nearest possibleFlowItem
)
-
transitTo
public boolean transitTo(FlowItem<?,?> target, Object context)
Transit to a specificFlowItem
in the flow- Parameters:
target
-FlowItem
to transition tocontext
- sets the context onContextExchange
which is used atFlowItem.parse(ContextExchange)
- Returns:
true
if transition is allowed,false
on config ofFlowItem.onBack(Condition[])
- Throws:
IllegalArgumentException
- if the label is not part of the flow or when the forward transition has not enough answers (will transition to the nearest possibleFlowItem
)
-
get
public FlowItem<?,?> get()
Get currentFlowItem
of the flow- Returns:
FlowItem
of the current flow
-
get
public FlowItem<?,?> get(String label)
Get a flow item by the givenString
To avoid cast its recommended to useFlowItem.get(FlowItem)
- Parameters:
label
- Thelabel
to search in flow- Returns:
Optional
ornull
when flow doesn't contain the requested item
-
get
public FlowItem<?,?> get(Enum<?> label)
Get a flow item by the givenenum
To avoid cast its recommended to useFlowItem.get(FlowItem)
- Parameters:
label
- Thelabel
to search in flow- Returns:
FlowItem
ornull
when flow doesn't contain the requested item
-
getPrevious
public FlowItem<?,?> getPrevious()
Get previousFlowItem
from the flow- Returns:
- previous
FlowItem
andnull
if there is no previous entry
-
getFirst
public FlowItem<?,?> getFirst()
Get firstFlowItem
of the flow- Returns:
- first
FlowItem
of the current flow
-
isEnded
public boolean isEnded()
Check if the current flow has ended- Returns:
- true if there is no next
FlowItem
-
getHistory
public List<HistoryItem> getHistory()
Get history of answers- Returns:
- all answers which were given in the context
-
getHistoryJson
public List<HistoryItemJson> getHistoryJson()
Get history of answers- Returns:
- all answers as json format which were given in the context
-
getHistorySize
public int getHistorySize()
Get history size- Returns:
- number of given answers
-
answer
public Survey answer(Object answer, Object context)
Solves the currentFlowItem
of the flow- Parameters:
answer
- answer to solve the currentFlowItem
context
- sets the context onContextExchange
which is used atFlowItem.parse(ContextExchange)
- Returns:
Survey
-
getDurationsMS
public Map<String,Long> getDurationsMS()
Returns times taken between each question useful to track answer times- Returns:
- times of answered questions
-
autoBackTransition
public Survey autoBackTransition(boolean enableAutomatic)
Defines if back transitions are allowed for non configured back conditions- Parameters:
enableAutomatic
-true
on default- Returns:
Survey
-
hasAutoBackTransition
public boolean hasAutoBackTransition()
Definition if back transitions are allowed for non configured back conditions- Returns:
true
on default
-
diagram
public DiagramExporter diagram()
Prepares diagram renderer- Returns:
DiagramExporter
renderer
-
findLast
protected FlowItem<?,?> findLast(LinkedList<HistoryItem> historySorted)
-
-