Class Survey

java.lang.Object
berlin.yuna.survey.logic.Survey

public class Survey extends Object
  • Method Details

    • init

      public static Survey init(FlowItem<?,?> flowStart)
      Starts new SurveyCtx
      Parameters:
      flowStart - start item of the flow
      Returns:
      Survey
      Throws:
      IllegalStateException - on null
    • init

      public static Survey init(FlowItem<?,?> flowStart, Iterable<? extends HistoryItemBase<?>> history)
      Continues Survey from a history Removes all invalid FlowItem items from the history
      Parameters:
      flowStart - start item of the flow
      history - should not be empty as Survey needs a start item
      Returns:
      Survey
      Throws:
      IllegalStateException - when the history is empty or has no valid FlowItem
    • transitTo

      public boolean transitTo(String label)
      Transit to a specific FlowItem in the flow
      Parameters:
      label - for FlowItem 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 specific FlowItem in the flow
      Parameters:
      label - for FlowItem to transition to
      context - sets the context on ContextExchange which is used at FlowItem.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 specific FlowItem in the flow
      Parameters:
      target - FlowItem to transition to
      Returns:
      true if transition is allowed, false on config of FlowItem.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 possible FlowItem)
    • transitTo

      public boolean transitTo(FlowItem<?,?> target, Object context)
      Transit to a specific FlowItem in the flow
      Parameters:
      target - FlowItem to transition to
      context - sets the context on ContextExchange which is used at FlowItem.parse(ContextExchange)
      Returns:
      true if transition is allowed, false on config of FlowItem.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 possible FlowItem)
    • get

      public FlowItem<?,?> get()
      Get current FlowItem of the flow
      Returns:
      FlowItem of the current flow
    • get

      public FlowItem<?,?> get(String label)
      Get a flow item by the given String To avoid cast its recommended to use FlowItem.get(FlowItem)
      Parameters:
      label - The label to search in flow
      Returns:
      Optional<FlowItem> or null when flow doesn't contain the requested item
    • get

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

      public <I extends FlowItem<?, ?>> I get(I type)
      Get a flow item by the given FlowItem
      Parameters:
      type - FlowItem to search in flow
      Returns:
      FlowItem or null when flow doesn't contain the requested item
    • getPrevious

      public FlowItem<?,?> getPrevious()
      Get previous FlowItem from the flow
      Returns:
      previous FlowItem and null if there is no previous entry
    • getFirst

      public FlowItem<?,?> getFirst()
      Get first FlowItem 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)
      Solves the current FlowItem of the flow
      Parameters:
      answer - answer to solve the current FlowItem
      Returns:
      Survey
    • answer

      public Survey answer(Object answer, Object context)
      Solves the current FlowItem of the flow
      Parameters:
      answer - answer to solve the current FlowItem
      context - sets the context on ContextExchange which is used at FlowItem.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)