Class IncrementalBuildState

java.lang.Object
nz.org.riskscape.wizard.bld.IncrementalBuildState

public class IncrementalBuildState extends Object

The results of building a pipeline incrementally in response to wizard Answers being supplied and PipelineChanges being made. This is a recursive data structure in that each state points to a previous state that was how the pipeline looked before the change was made.

  • Field Details

    • START_STEP_NAME

      public static final String START_STEP_NAME

      The non-answer for an empty question. Again, used instead of null in various situations.

      See Also:
    • EMPTY_QUESTION_SET

      public static final QuestionSet EMPTY_QUESTION_SET

      The QuestionSet associated with an empty build state, i.e. when isEmpty() is true

    • EMPTY_QUESTION

      public static final Question EMPTY_QUESTION

      The Question associated with an empty build state, i.e. when isEmpty() is true

    • EMPTY_ANSWER

      public static final Answer EMPTY_ANSWER
    • START_STEPS_SET

      public static final Set<nz.org.riskscape.engine.pipeline.RealizedStep> START_STEPS_SET

      A set of RealizedStep that is returned from a QuestionSet's applicability method when it applies to an empty pipeline

  • Constructor Details

  • Method Details

    • empty

      Create a new, empty incremental build state using the given dependencies. This is the start state for building a pipeline incrementally via a Survey.

    • append

      public IncrementalBuildState append(@NonNull @NonNull PipelineChange newCreatedBy, @NonNull @NonNull nz.org.riskscape.pipeline.ast.PipelineDeclaration newAst, @NonNull @NonNull nz.org.riskscape.engine.pipeline.RealizedPipeline newPipeline) throws IllegalArgumentException

      Return a new IncrementalBuildState that resulted in applying the given change to this build state.

      Parameters:
      newCreatedBy - The PipelineChange that is responsible
      newAst - The pipeline ast that the PipelineChange created
      newPipeline - An illustrative fragment of the pipeline, used for validation purposes (so far)
      Throws:
      IllegalArgumentException - if the change references an Answer for a Question that has already been answered
    • buildStateIterator

      public Iterator<IncrementalBuildState> buildStateIterator()
      Returns:
      an Iterator that traverses the build state's stack, from latest change to oldest, excluding the empty state
    • buildStateStream

      public Stream<IncrementalBuildState> buildStateStream()
      Returns:
      a Stream that traverses the build state's stack, from latest change to oldest, excluding the empty state
    • isInvalid

      public boolean isInvalid()
      Returns:
      true if this state has resulted in an invalid pipeline. Please try again.
    • getRealizedStep

      public nz.org.riskscape.engine.pipeline.RealizedStep getRealizedStep() throws IllegalStateException

      Attempts to return the end step that resulted from this state.

      Will return the single (non-sink) end step if one exists. Otherwise if there are only SinkConstructor end steps then their dependency will be returned if that is the same for all of the sinks. Otherwise the IllegalStateException is thrown.

      Throws:
      IllegalStateException - If there is none, or there were multiple end steps, then this throws an exception
    • getInputStruct

      public nz.org.riskscape.engine.types.Struct getInputStruct(ChangeLocation location)
      Returns:
      the input scope Struct based on location, if known. Returns EMPTY_STRUCT if it couldn't be determined.
    • getInputStruct

      public nz.org.riskscape.engine.types.Struct getInputStruct(Question question)
      Returns:
      the input scope Struct available for this question, if known. Returns EMPTY_STRUCT if it couldn't be determined.
    • isEmpty

      public boolean isEmpty()
      Returns:
      true if this build state is the first, empty state.
    • getAnswer

      public Optional<Answer> getAnswer(String questionSetId, String questionName)
    • getAnswer

      public Optional<Answer> getAnswer(Question q)
      Returns:
      return an answer for the given question, based on the question's id (rather than testing object ==)
    • getResponse

      public <T> Optional<T> getResponse(String questionSetId, String questionName, Class<T> expectedResponseType)

      Optional-style version of getAnswerTo

    • getAnswersTo

      public <T> List<T> getAnswersTo(String questionSetId, String questionName, Class<T> expectedType)
      Returns:
      the responses recorded for a given question
    • getAnswerTo

      public <T> T getAnswerTo(String questionSetId, String questionName, Class<T> expectedType)
      Returns:
      the response recorded for a question, throwing an exception if the question wasn't a single-value response type question
    • realizePipeline

      public nz.org.riskscape.engine.pipeline.RealizedPipeline realizePipeline(nz.org.riskscape.engine.pipeline.Pipeline pipeline)

      Helper method for changes etc to realize a pipeline that was created from a PipelineDeclaration (so no supplementary parameters required)

      Returns:
      RealizedPipeline
    • realizePipeline

      public nz.org.riskscape.problem.ResultOrProblems<nz.org.riskscape.engine.pipeline.RealizedPipeline> realizePipeline(nz.org.riskscape.pipeline.ast.PipelineDeclaration realizeThisAst)

      Helper method for attempting to construct and realize a pipeline from the given ast TODO see about moving this to ExecutionContext or PipelineExecutor, so that we can more easily go straight from AST to RealizedPipeline

    • getBuilder

      public nz.org.riskscape.engine.pipeline.PipelineBuilder getBuilder()
      Returns:
      a PipelineBuilder for constructing Pipelines TODO move to some sort of base pipeline change class?
    • getAnswer

      public Answer getAnswer()
      Returns:
      the Answer that resulted in this build state
    • getQuestionSet

      public QuestionSet getQuestionSet()
      Returns:
      the QuestionSet linked to this build state, e.g the question and answer belonged to this QuestionSet
    • getQuestion

      public Question getQuestion()
      Returns:
      the Question who's answer resulted in the build state
    • getProject

      public nz.org.riskscape.engine.Project getProject()
      Returns:
      the Project associated with this build state
    • getAllAnswers

      public List<Answer> getAllAnswers()
      Returns:
      all that answers in the buildstate, in the order they were most recently given, i.e the head of the list is the same as this build state's getAnswer()
    • isQuestionSetAnswered

      public boolean isQuestionSetAnswered(String questionSetId)

      Determine whether a question set with the given id appears in this build state's change stack, indicating that the question set has been responded to or skipped

    • wasAsked

      public boolean wasAsked(String questionSetId, String questionName)

      Determine whether a question has been asked, regardless of whether the user provided a response or just chose to skip the question.

      This method accepts id strings, rather than the actual objects, to allow other questions to test for their presence without needing a reference to the other question

      Returns:
      true if the given question was answered, regardless of whether a response was given.
    • lastAnswerWas

      public boolean lastAnswerWas(Object value)

      Returns true if the last answer was the given value. This only checks the answer supplied for single-valued Questions, so it will always return false if the question is not single valued.

    • isResponseGiven

      public boolean isResponseGiven(String questionSetId, String questionName)

      Determine whether a response has been given to a question by its name local to the current question set.

      This method accepts id strings, rather than the actual objects, to allow other questions to test for their presence without needing a reference to the other question

      Returns:
      true if the given question was answered and at least one response was given.
    • ifResponseGiven

      public <T> boolean ifResponseGiven(String questionSetId, String questionName, Class<T> clazz, Consumer<T> callback)

      Functional style if that calls the callback if a response was given to the nominated question, returning true if the callback was called

    • getBindingContext

      public nz.org.riskscape.engine.bind.BindingContext getBindingContext()
      Returns:
      the BindingContext associated with this pipeline build state's context
    • getPipelineExecutor

      public nz.org.riskscape.engine.pipeline.PipelineExecutor getPipelineExecutor()
      Returns:
      the PipelineExecutor associated with this pipeline build state's context
    • getSurvey

      public Survey getSurvey()
    • toString

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

      public boolean isResponseGiven()
      Returns:
      true if the build state was in response to a human entering some information, i.e not skipped and not hidden
    • rewind

      public IncrementalBuildState rewind()

      Removes trailing build states that have no response. These could either be hidden questions or optional questions that were not answered.

      Returns:
      the last build with a response, or the empty build state if none found
    • getContext

      public IncrementalBuildState.Context getContext()

      Various static dependencies, i.e. this is the same object for all members of the change stack

    • getLast

      public IncrementalBuildState getLast()

      The previous thing we built upon - will return this if this is the empty build state

    • getCreatedBy

      public PipelineChange getCreatedBy()

      The change that was responsible for this state being created

    • getAst

      public nz.org.riskscape.pipeline.ast.PipelineDeclaration getAst()

      The current pipeline ast.

    • getRealizedPipeline

      public nz.org.riskscape.engine.pipeline.RealizedPipeline getRealizedPipeline()

      A small chunk of the overall pipeline that was realized for this state to be proven valid.

    • equals

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

      protected boolean canEqual(Object other)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object