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<?,​?>>
  • Constructor Details

    • QuestionGeneric

      protected QuestionGeneric​(String label)
  • Method Details

    • get

      public static QuestionGeneric<?,​?> get​(Enum<?> label)
      Returns the specified QuestionGeneric which is the specified by this label
      Parameters:
      label - The label which is configured for the specified label
      Returns:
      QuestionGeneric found by the label or null if there is no configuration for it
    • get

      public static QuestionGeneric<?,​?> get​(String label)
      Returns the specified QuestionGeneric which is the specified by this label
      Parameters:
      label - The label which is configured for the specified label
      Returns:
      QuestionGeneric found by the label or null if there is no configuration for it
    • getOrElse

      public static QuestionGeneric<?,​?> getOrElse​(String label, QuestionGeneric<?,​?> fallback)
      Returns the specified QuestionGeneric which is the specified by this label
      Parameters:
      label - The label which is configured for the specified label
      fallback - if no question was found label
      Returns:
      QuestionGeneric found by the label or null if there is no configuration for it
    • clearAll

      public static void clearAll()
      Removes all of the configured mappings
    • exists

      public static boolean exists​(Enum<?>... label)
      Parameters:
      label - label to check for
      Returns:
      true if there is a configuration for the specified label QuestionGeneric exists
    • containsTarget

      public boolean containsTarget​(QuestionGeneric<?,​?> question)
      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 current QuestionGeneric 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 start
      question - QuestionGeneric to check if its contained in the flow
      Returns:
      true if the question is linked in flowStart
    • getParentsOf

      public Set<QuestionGeneric<?,​?>> getParentsOf​(QuestionGeneric<?,​?> question)
      Returns a set of parent QuestionGeneric
      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 parent QuestionGeneric
      Parameters:
      flowStart - QuestionGeneric of the flow start
      question - QuestionGeneric to find the parent of in the flow
      Returns:
      a set of parents - set will be empty if no parent was found
    • exists

      public static boolean exists​(String... label)
      Parameters:
      label - label to check for
      Returns:
      true if there is a configuration for the specified label QuestionGeneric exists
    • target

      public C target​(QuestionGeneric<?,​?> target)
      Defines the next target QuestionGeneric which will come after calling answer() or answer(Object)
      Parameters:
      target - defines the target which comes after answering
      Returns:
      returns the current object
    • target

      public C target​(QuestionGeneric<?,​?> target, Function<T,​Boolean> condition)
      Defines the next target QuestionGeneric which will come after calling answer() or answer(Object) when the condition is given
      Parameters:
      target - defines the target which comes after answering
      condition - condition which mussed be true to route to the specified target. Can be null if no condition needs to be matched see target()
      Returns:
      returns the current object
    • target

      public C target​(QuestionGeneric<?,​?> target, Choice<T> condition)
      Defines the next target QuestionGeneric which will come after calling answer() or answer(Object) when the condition is given
      Parameters:
      target - defines the target which comes after answering
      condition - condition which mussed be true to route to the specified target. Can be null if no condition needs to be matched see target()
      Returns:
      returns the current object
    • targetGet

      public <I extends QuestionGeneric<?,​ ?>> I targetGet​(I target)
      Defines the next target QuestionGeneric which will come after calling answer() or answer(Object)
      Parameters:
      target - defines the target which comes after answering
      Returns:
      returns the target object
    • targetGet

      public <I extends QuestionGeneric<?,​ ?>> I targetGet​(I target, Function<T,​Boolean> condition)
      Defines the next target QuestionGeneric which will come after calling answer() or answer(Object)
      Parameters:
      target - defines the target which comes after answering
      condition - condition which mussed be true to route to the specified target. Can be null if no condition needs to be matched see target()
      Returns:
      returns the target object
    • targetGet

      public <I extends QuestionGeneric<?,​ ?>> I targetGet​(I target, Choice<T> condition)
      Defines the next target QuestionGeneric which will come after calling answer() or answer(Object)
      Parameters:
      target - defines the target which comes after answering
      condition - condition which mussed be true to route to the specified target. Can be null if no condition needs to be matched see target()
      Returns:
      returns the target object
    • target

      public Set<QuestionGeneric<?,​?>> target()
      Returns a Set with all configured targets
      Returns:
      a set view of all configured targets for this QuestionGeneric object
    • answer

      public Optional<QuestionGeneric<?,​?>> answer()
      Answers the question with null and returns next question
      Returns:
      empty if there is no next question configured
    • parse

      public abstract Optional<T> parse​(Object answer)
      Converts input to the answer type for answer(Object) Its also used within parseAndAnswer(Object)
      Parameters:
      answer - input parameter to be parsed target(QuestionGeneric) (Object)}
      Returns:
      depends on the implementation - null usually means its not parsable which needs to be cached at
    • parseAndAnswer

      public Optional<QuestionGeneric<?,​?>> parseAndAnswer​(Object answer)
      Converts input and returns next QuestionGeneric which is configured fot the answer at target(QuestionGeneric) (Object)}
      Parameters:
      answer - input parameter
      Returns:
      Optional.empty() when question doesn't match configuration - see target(QuestionGeneric) (Object)}
    • answer

      public Optional<QuestionGeneric<?,​?>> answer​(T answer)
      Returns next QuestionGeneric which is configured fot the answer at target(QuestionGeneric) (Object)}
      Parameters:
      answer - input parameter
      Returns:
      returns next QuestionGeneric which is configured at target(QuestionGeneric) (Object)}
    • label

      public String label()
      Returns:
      label
    • match

      public boolean match​(SurveyAnswer answer)
      Parameters:
      answer - input for check
      Returns:
      true if SurveyAnswer relates to the current QuestionGeneric
    • onBack

      public boolean onBack​(Object answer)
      Triggers the on back function which is configured at onBack(Consumer)
      Parameters:
      answer - input for on back checks
      Returns:
      true on default or false when configured at onBack(Consumer)
    • onBack

      public C onBack​(Consumer<T> onBack)
      Defines what happens when a back transition is requested
      Parameters:
      onBack - function which decides what happens when back transition is triggered see onBack(Object)
      Returns:
      returns the current object
    • routes

      public Set<QuestionGeneric.AnswerRoute<T>> routes()
    • getOrNew

      protected static <K> K getOrNew​(String label, Class<K> type, Supplier<K> instance)
    • 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​(QuestionGeneric o)
      Specified by:
      compareTo in interface Comparable<T>