Class IncrementalBuildState
The results of building a pipeline incrementally in response to wizard Answer
s being supplied and
PipelineChange
s 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
Modifier and TypeClassDescriptionstatic class
All the unchanging elements of theIncrementalBuildState
, wrapped up in a class for ease of copying/referencing. -
Field Summary
Modifier and TypeFieldDescriptionstatic final Answer
static final Question
TheQuestion
associated with an empty build state, i.e.static final QuestionSet
The QuestionSet associated with an empty build state, i.e.static final String
The non-answer for an empty question.static final Set<nz.org.riskscape.engine.pipeline.RealizedStep>
A set ofRealizedStep
that is returned from a QuestionSet's applicability method when it applies to an empty pipeline -
Constructor Summary
ModifierConstructorDescriptionprotected
IncrementalBuildState
(IncrementalBuildState.Context context, IncrementalBuildState last, PipelineChange createdBy, nz.org.riskscape.pipeline.ast.PipelineDeclaration ast, nz.org.riskscape.engine.pipeline.RealizedPipeline realizedPipeline) -
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 newIncrementalBuildState
that resulted in applying the given change to this build state.protected boolean
static IncrementalBuildState
empty
(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> T
getAnswerTo
(String questionSetId, String questionName, Class<T> expectedType) nz.org.riskscape.pipeline.ast.PipelineDeclaration
getAst()
The current pipeline ast.nz.org.riskscape.engine.bind.BindingContext
nz.org.riskscape.engine.pipeline.PipelineBuilder
Various static dependencies, i.e.The change that was responsible for this state being creatednz.org.riskscape.engine.types.Struct
getInputStruct
(ChangeLocation location) nz.org.riskscape.engine.types.Struct
getInputStruct
(Question question) getLast()
The previous thing we built upon - will returnthis
if this is the empty build statenz.org.riskscape.engine.pipeline.PipelineExecutor
nz.org.riskscape.engine.Project
nz.org.riskscape.engine.pipeline.RealizedPipeline
A small chunk of the overall pipeline that was realized for this state to be proven valid.nz.org.riskscape.engine.pipeline.RealizedStep
Attempts 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 getAnswerToint
hashCode()
<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 calledboolean
isEmpty()
boolean
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 skippedboolean
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.boolean
lastAnswerWas
(Object value) Returns true if the last answer was the given value.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 aPipelineDeclaration
(so no supplementary parameters required)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 RealizedPipelinerewind()
Removes trailing build states that have no response.toString()
boolean
Determine 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
RealizedStep
that 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)
-
-
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
- ThePipelineChange
that is responsiblenewAst
- The pipeline ast that thePipelineChange
creatednewPipeline
- An illustrative fragment of the pipeline, used for validation purposes (so far)- Throws:
IllegalArgumentException
- if the change references anAnswer
for aQuestion
that has already been answered
-
buildStateIterator
- Returns:
- an
Iterator
that traverses the build state's stack, from latest change to oldest, excluding the empty state
-
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
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
- 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.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 constructingPipeline
s TODO move to some sort of base pipeline change class?
-
getAnswer
- Returns:
- the
Answer
that 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
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
- 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
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
-
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
this
if 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()
-