Class FlowItem<T,C extends FlowItem<T,C>>

java.lang.Object
berlin.yuna.survey.model.types.FlowItem<T,C>
Type Parameters:
T - Item type
C - 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<?,?>>
The FlowItem defines a user flow which is used by Survey to keep track on the history
  • Constructor Details

    • FlowItem

      public FlowItem(String label)
  • Method Details

    • get

      public Optional<FlowItem<?,?>> get(Enum<?> label)
      Get a flow item by the given enum
      Parameters:
      label - The label to search in flow
      Returns:
      Optional<FlowItem> or Optional.empty() when flow doesn't contain the requested item
    • get

      public Optional<FlowItem<?,?>> get(String label)
      Get a flow item by the given String
      Parameters:
      label - The label to search in flow
      Returns:
      Optional<FlowItem> or Optional.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 given FlowItem
      Parameters:
      type - FlowItem to search in flow
      Returns:
      Optional<FlowItem> or Optional.empty() when flow doesn't contain the requested item
    • getOrElse

      public FlowItem<?,?> getOrElse(String label, FlowItem<?,?> fallback)
      Get a flow item by this String
      Parameters:
      label - The label to search in flow
      fallback - FlowItem to return if the flow item wasn't found
      Returns:
      FlowItem or fallback when flow doesn't contain the requested item
    • getOrElse

      public FlowItem<?,?> getOrElse(Enum<?> label, FlowItem<?,?> fallback)
      Get a flow item by this enum
      Parameters:
      label - The label to search in flow
      fallback - FlowItem to return if the flow item wasn't found
      Returns:
      FlowItem or fallback when flow doesn't contain the requested item
    • getOrElse

      public <I extends FlowItem<?, ?>> I getOrElse(I type, I fallback)
      Get a flow item by this type
      Parameters:
      type - The label to search in flow
      fallback - FlowItem to return if the flow item wasn't found
      Returns:
      FlowItem or fallback when flow doesn't contain the requested item
    • target

      public C target(FlowItem<?,?> target)
      Defines a transition target of targets() 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 of targets()
      Parameters:
      target - defines the transition target
      condition - condition to match. On true 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 of targets()
      Parameters:
      target - defines the transition target
      condition - condition to match. On true 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 of targets()
      Parameters:
      target - defines the transition target
      condition - condition to match. On true 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 of targets()
      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 of targets()
      Parameters:
      target - defines the transition target
      condition - condition to match. On true 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 of targets()
      Parameters:
      target - defines the transition target
      condition - condition to match. On true will execute the transition - Conditions can be also used to trigger a process
      Returns:
      target object
    • targets

      public Set<FlowItem<?,?>> targets()
      Returns a Set with all configured targets
      Returns:
      a set view of all configured targets for this FlowItem object
    • onBack

      public C onBack(Function<T,Boolean> condition)
      Defines a back transition of targets()
      Parameters:
      condition - condition to match. On true 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 of targets()
      Parameters:
      conditions - condition to match. On true 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 of targets()
      Parameters:
      conditions - condition to match. On true will execute the transition - Conditions can be also used to trigger a process
      Returns:
      current object
    • targetsBack

      public Set<FlowItem<?,?>> targetsBack()
      Returns a Set with all configured targets
      Returns:
      a set view of all configured targets for this FlowItem object
    • parents

      public Set<FlowItem<?,?>> parents()
      Returns a Set with all configured targets
      Returns:
      a set view of all configured targets for this FlowItem object
    • parse

      public abstract Optional<T> parse(ContextExchange context)
      (Optional) Input converter to handle the answer - used to solve parseAndApply(ContextExchange, Function)
      Parameters:
      context - input parameter to be parsed for the condition of a configured Route
      Returns:
      Optional.empty() to used the default cast and JSON parser parseAndApply(ContextExchange, Function)
    • parseAndAnswer

      public Optional<FlowItem<?,?>> parseAndAnswer(ContextExchange context)
      Returns next FlowItem 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 next FlowItem which is configured for a back transition
      Parameters:
      context - input parameter
      function - 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 next FlowItem 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 next FlowItem 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 if HistoryItem relates to the current FlowItem
    • transitions

      public TransitionSet<T> transitions()
      Returns:
      a copy of configured routes
    • routes

      public Set<Route<T>> routes()
      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)
      Search FlowItem in current flow
      Parameters:
      search - type to search in flow
      Returns:
      Optional.empty() of not found
    • addParent

      protected void addParent(FlowItem<?,?> parent)
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • compareTo

      public int compareTo(FlowItem o)
      Specified by:
      compareTo in interface Comparable<T>