Class BasePhase

java.lang.Object
nz.org.riskscape.wizard.survey2.BasePhase
All Implemented Interfaces:
Phase
Direct Known Subclasses:
AnalysisPhase, InputDataPhase, ReportPhase, SamplePhase

public class BasePhase extends Object implements Phase

Base implementation of a phase that takes care of the links between the survey, they phase and the question sets.

  • Field Details

    • survey

      protected final Survey survey
    • skippableQuestionSets

      protected final Set<String> skippableQuestionSets
    • builtQuestionSets

      protected List<? extends QuestionSet> builtQuestionSets
  • Constructor Details

  • Method Details

    • simple

      public static BasePhase simple(Survey survey, String qsId, boolean skippable, Consumer<DefaultQuestionSet2> consumer)

      Create a BasePhase that wraps a single question set

      Parameters:
      qsId - id to assign to the question set
      skippable - true if this question set, and thus the entire phase, can be skipped
      consumer - a function that allows you to add questions to the question set that belongs to the phase
    • isComplete

      public boolean isComplete(IncrementalBuildState buildState)
      Returns:
      true if there are no more question sets that can be answered
    • getAvailableQuestionSets

      public List<QuestionSet> getAvailableQuestionSets(IncrementalBuildState buildState)

      Default implementation of Phase#getAvailableQuestionSets(IncrementalBuildState) that builds a static list of question sets the first time it sees a build state and then filters them based on what's already been answered

    • builtQuestionsInvalid

      protected boolean builtQuestionsInvalid(IncrementalBuildState buildState)

      Determine whether question sets need rebuilding, will always return false if the phase was constructed with a single static question set. Returns true if the given build state doesn't contain the build state (in its stack) that the phase used to build the question sets it already has.

    • buildQuestionSets

      protected List<QuestionSet> buildQuestionSets(IncrementalBuildState buildState)
    • buildQuestionSet

      protected QuestionSet buildQuestionSet(IncrementalBuildState buildState)
    • canSkip

      public boolean canSkip(IncrementalBuildState buildState)
      Returns:
      true if the remaining question sets in this phase can be skipped, or false if they must be answered to move on to the next phase
    • contains

      public boolean contains(QuestionSet questionSet)
      Returns:
      true if the given question set belongs to this phase. Used by the survey code to track a build state back to a phase
    • getName

      public Optional<String> getName(Locale locale)
      Specified by:
      getName in interface Phase
      Returns:
      a short name for this phase, translated in to the given locale
    • getSurvey

      public Survey getSurvey()
      Specified by:
      getSurvey in interface Phase
      Returns:
      the survey that this phase belongs to