Class IncrementalBuildState
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAll the unchanging elements of theIncrementalBuildState, wrapped up in a class for ease of copying/referencing. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Answerstatic final QuestionTheQuestionassociated with an empty build state, i.e.static final QuestionSetThe QuestionSet associated with an empty build state, i.e.static final StringThe non-answer for an empty question.static final Set<nz.org.riskscape.engine.pipeline.RealizedStep>A set ofRealizedStepthat is returned from a QuestionSet's applicability method when it applies to an empty pipeline -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedIncrementalBuildState(IncrementalBuildState.Context context, IncrementalBuildState last, PipelineChange createdBy, nz.org.riskscape.pipeline.ast.PipelineDeclaration ast, nz.org.riskscape.engine.pipeline.RealizedPipeline realizedPipeline) Creates a newIncrementalBuildStateinstance. -
Method Summary
Modifier and TypeMethodDescriptionappend(@NonNull PipelineChange newCreatedBy, @NonNull nz.org.riskscape.pipeline.ast.PipelineDeclaration newAst, @NonNull nz.org.riskscape.engine.pipeline.RealizedPipeline newPipeline) Return a newIncrementalBuildStatethat resulted in applying the given change to this build state.protected booleanstatic IncrementalBuildStateempty(IncrementalBuildState.Context context) Create a new, empty incremental build state using the given dependencies.boolean<T> List<T>getAnswersTo(String questionSetId, String questionName, Class<T> expectedType) <T> TgetAnswerTo(String questionSetId, String questionName, Class<T> expectedType) nz.org.riskscape.pipeline.ast.PipelineDeclarationgetAst()The current pipeline ast.nz.org.riskscape.engine.bind.BindingContextVarious static dependencies, i.e.The change that was responsible for this state being creatednz.org.riskscape.engine.types.StructgetInputStruct(ChangeLocation location) nz.org.riskscape.engine.types.StructgetInputStruct(Question question) getLast()The previous thing we built upon - will returnthisif this is the empty build statenz.org.riskscape.engine.pipeline.PipelineExecutornz.org.riskscape.engine.Projectnz.org.riskscape.engine.pipeline.RealizedPipelineA small chunk of the overall pipeline that was realized for this state to be proven valid.nz.org.riskscape.engine.pipeline.RealizedStepAttempts to return the end step that resulted from this state.<T> Optional<T>getResponse(String questionSetId, String questionName, Class<T> expectedResponseType) Optional-style version of getAnswerTointhashCode()<T> booleanifResponseGiven(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 calledbooleanisEmpty()booleanbooleanisQuestionSetAnswered(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 skippedbooleanbooleanisResponseGiven(String questionSetId, String questionName) Determine whether a response has been given to a question by its name local to the current question set.booleanlastAnswerWas(Object value) Returns true if the last answer was the given value.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.rewind()Removes trailing build states that have no response.toString()booleanDetermine whether a question has been asked, regardless of whether the user provided a response or just chose to skip the question.
-
Field Details
-
START_STEP_NAME
The non-answer for an empty question. Again, used instead of null in various situations.
- See Also:
-
EMPTY_QUESTION_SET
The QuestionSet associated with an empty build state, i.e. when
isEmpty()is true -
EMPTY_QUESTION
-
EMPTY_ANSWER
-
START_STEPS_SET
A set of
RealizedStepthat is returned from a QuestionSet's applicability method when it applies to an empty pipeline
-
-
Constructor Details
-
IncrementalBuildState
protected IncrementalBuildState(IncrementalBuildState.Context context, IncrementalBuildState last, PipelineChange createdBy, nz.org.riskscape.pipeline.ast.PipelineDeclaration ast, nz.org.riskscape.engine.pipeline.RealizedPipeline realizedPipeline) Creates a new
IncrementalBuildStateinstance.- Parameters:
context- Various static dependencies, i.e. this is the same object for all members of the change stacklast- The previous thing we built upon - will returnthisif this is the empty build statecreatedBy- The change that was responsible for this state being createdast- The current pipeline ast.realizedPipeline- A small chunk of the overall pipeline that was realized for this state to be proven valid.
-
-
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
IncrementalBuildStatethat resulted in applying the given change to this build state.- Parameters:
newCreatedBy- ThePipelineChangethat is responsiblenewAst- The pipeline ast that thePipelineChangecreatednewPipeline- An illustrative fragment of the pipeline, used for validation purposes (so far)- Throws:
IllegalArgumentException- if the change references anAnswerfor aQuestionthat has already been answered
-
buildStateIterator
- Returns:
- an
Iteratorthat traverses the build state's stack, from latest change to oldest, excluding the empty state
-
buildStateStream
- Returns:
- a
Streamthat 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
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
SinkConstructorend 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
- Returns:
- the input scope Struct based on
location, if known. Returns EMPTY_STRUCT if it couldn't be determined.
-
getInputStruct
- 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
-
getAnswer
- 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
- Returns:
- the responses recorded for a given question
-
getAnswerTo
- 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.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. NB: We can probably drop the
ResultOrProblemsfrom this - a RealizedPipeline has its own list of errors. -
getAnswer
- Returns:
- the
Answerthat resulted in this build state
-
getQuestionSet
- Returns:
- the QuestionSet linked to this build state, e.g the question and answer belonged to this QuestionSet
-
getQuestion
- Returns:
- the
Questionwho's answer resulted in the build state
-
getProject
public nz.org.riskscape.engine.Project getProject()- Returns:
- the
Projectassociated with this build state
-
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
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
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
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
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
BindingContextassociated with this pipeline build state's context
-
getPipelineExecutor
public nz.org.riskscape.engine.pipeline.PipelineExecutor getPipelineExecutor()- Returns:
- the
PipelineExecutorassociated with this pipeline build state's context
-
getSurvey
-
toString
-
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
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
Various static dependencies, i.e. this is the same object for all members of the change stack
-
getLast
The previous thing we built upon - will return
thisif this is the empty build state -
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
-
canEqual
-
hashCode
public int hashCode()
-