Class QuestionTree
Imposes an ordered-tree structure on to a list of questions to centralize the logic of moving through a set of questions in the order that the questions impose with their dependencies and order in relation to each other.
-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic QuestionTree
empty()
find
(Predicate<QuestionTree.Node> predicate) Find all the nodes in the tree that match the given predicate in breadth-first orderfindOne
(Predicate<QuestionTree.Node> predicate) Find a single node in the tree using the given predicatefindQuestion
(Question question) Locate the node that points to the given questionstatic QuestionTree
Builds a QuestionTree by searching through the questions in order and building a tree from their dependencies.getNextQuestions
(IncrementalBuildState buildState) Query the tree to find the list of questions that should be presented to the user as being asked next.getRoot()
The root of the tree - note that the question here is a placeholder and should never be asked - this is to make it simpler to support multiple questions without any dependencies - these questions are children of the root.getSkipped
(IncrementalBuildState buildState, Question chosen) boolean
isComplete
(IncrementalBuildState buildState) boolean
isEmpty()
static QuestionTree
<T> T
visitBfs
(BiConsumer<QuestionTree.Node, T> consumer, T data) Simpler version ofvisitBfs(BiFunction, Object)
that doesn't require the visitor to return data - it just returns whatever was given as thedata
parameter<T> T
visitBfs
(BiFunction<QuestionTree.Node, T, T> consumer, T data) Visit the tree in breadth first order
-
Method Details
-
singleton
-
empty
-
fromList
Builds a QuestionTree by searching through the questions in order and building a tree from their dependencies. Questions that share the same dependency are ordered relative to each other in the list such that any question that is before another is also asked/considered in that order.
-
visitBfs
Visit the tree in breadth first order
- Parameters:
consumer
- a function to call that accepts each node that should return some data of the same type to be passed to the next nodedata
- some data to pass between visits, could be a list or an AtomicReference or whatever- Returns:
- the data that was given
-
visitBfs
Simpler version of
visitBfs(BiFunction, Object)
that doesn't require the visitor to return data - it just returns whatever was given as thedata
parameter -
find
Find all the nodes in the tree that match the given predicate in breadth-first order
-
findOne
Find a single node in the tree using the given predicate
-
findQuestion
Locate the node that points to the given question
-
isEmpty
public boolean isEmpty()- Returns:
- if there are no questions in this tree
-
getNextQuestions
Query the tree to find the list of questions that should be presented to the user as being asked next. The first question must be answered first, even if it is skipped (by supplying an empty response).
-
isComplete
- Returns:
- true if no more questions can be answered from this tree.
-
getSkipped
- Returns:
- a list of questions that are being skipped if the next question to be answered is
chosen
. These should be skipped via theSurvey2#skip(IncrementalBuildState, Question)
method.
-
getRoot
The root of the tree - note that the question here is a placeholder and should never be asked - this is to make it simpler to support multiple questions without any dependencies - these questions are children of the root.
-