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, with no custom backing data provided by the phase

      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
    • simple

      public static BasePhase simple(Survey survey, String qsId, boolean skippable, Consumer<DefaultQuestionSet2> consumer, BiFunction<IncrementalBuildState,Question,BackingData> backingDataFunction)

      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
      backingDataFunction - a callback for returning per-question backing data
    • 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

      Specified by:
      getAvailableQuestionSets in interface Phase
    • 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)
      Specified by:
      canSkip in interface Phase
      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
    • getBackingData

      public BackingData getBackingData(IncrementalBuildState buildState, Question question)
      Description copied from interface: Phase

      Allows a survey to delegate backing data requests to the phase that served up the question

      Specified by:
      getBackingData in interface Phase
    • contains

      public boolean contains(QuestionSet questionSet)
      Specified by:
      contains in interface Phase
      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
    • getSurvey

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