Interface DirectedGraphNode<P extends Enum<?>,A extends DirectedGraphNode<P,A,?>,T extends DirectedGraphNode<P,A,T>>
- Type Parameters:
P- Property TypeA- Abstract Type that all nodes will haveT- Specific Type of this node
- All Known Implementing Classes:
ApplicationModule.Builder,ConfirmationPrompt,ContainerModule.Builder,FunctionModule.Builder,InputHandler,ModuleTemplate,NumberedList,NumberedModuleSelector,PasswordInput,TextChain,TextInputModule.Builder,TextModule.Builder,TUIModule.Builder
This class is not Thread-Safe.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic enumSpecifies behavior for updating a property of this node. -
Method Summary
Modifier and TypeMethodDescriptiondefault Adefault booleanTraverses through every node accessible from this node and returns true if one of the nodes is null.default booleancontainsNullNode(Set<A> visited) Traverses through every node accessible from this node and returns true if one of the nodes is null.default AExecutes a DFS on self and all accessible children of the graph.default AExecutes a DFS on self and all accessible children of the graph.default voidExecutes the Consumer on self and every accessible node of the graph.default voidforEachChild(Consumer<A> function) Executes the Consumer on every accessible node of the graph, excluding this one.Connections between nodes are established by giving a node "children".Get the map of the flag set for each property.getType()Get theClass<T>type of the current Nodedefault Tself()booleanshallowStructuralEquals(T first, T second) default booleanstructuralEquals(A other) Checks for structural equality with another node based on equalityCriteria.default booleanstructuralEquals(A other, Set<A> visited) Checks for equality with another node based on equalTo.default voidupdateProperty(P property, Consumer<A> updater) Updates this node based on the flag of a property.default voidUpdates this node based on the flag of a property.
-
Method Details
-
getChildren
Connections between nodes are established by giving a node "children".
The direction goes from this node to the child nodes.- Returns:
- The list of children of this node.
- Implementation Requirements:
- Must return a non-null list (may be empty).
-
getPropertyUpdateFlags
Map<P,DirectedGraphNode.PropertyUpdateFlag> getPropertyUpdateFlags()Get the map of the flag set for each property.
- Returns:
- The map that associates each property with its corresponding update flag.
- Implementation Requirements:
- Every property that may be used should have a default flag
(e.g.,
DirectedGraphNode.PropertyUpdateFlag.UPDATE) present in this map. Implementations must ensure that this map is non-null and contains a flag for every property that will be passed toupdateProperty.
-
getType
Get theClass<T>type of the current Node -
dfs
Executes a DFS on self and all accessible children of the graph. Cycles are supported. Null Nodes are skipped.- Parameters:
criteria- A function that checks whether a child should be returned- Returns:
- The first found child (DFS), or null if none is found
-
dfs
Executes a DFS on self and all accessible children of the graph. Cycles are supported.- Parameters:
criteria- A function that checks whether a child should be returnedvisited- used so we can keep track of the modules we've visited and thus support cycles- Returns:
- The first found child (DFS), or null if none is found
-
forEach
Executes the Consumer on self and every accessible node of the graph. Cycles are supported. Null Nodes are skipped.- Parameters:
function- The Consumer that accepts every accessible node.
-
forEachChild
Executes the Consumer on every accessible node of the graph, excluding this one. Cycles are supported.Note: This node will not be updated even if cycled back to by another node.
- Parameters:
function- The Consumer that accepts every accessible node.
-
containsNullNode
default boolean containsNullNode()Traverses through every node accessible from this node and returns true if one of the nodes is null. Cycles are supported.- Returns:
- Whether a null node is accessible (directly or indirectly) from this node.
-
containsNullNode
Traverses through every node accessible from this node and returns true if one of the nodes is null. Cycles are supported.- Parameters:
visited- used so we can keep track of the modules we've visited and thus support cycles- Returns:
- Whether a null node is accessible (directly or indirectly) from this node.
-
updateProperty
Updates this node based on the flag of a property. Utilizes the flag for each property to determine traversal.
Assuming all flags are set to UPDATE, traversal is depth-first.
- Parameters:
property- The property to check the flag for.updater- The function that updates this node.visited- The set of nodes that have already been visited.
-
updateProperty
Updates this node based on the flag of a property. Utilizes the flag for each property to determine traversal.
Assuming all flags are set to UPDATE, traversal is depth-first.
- Parameters:
property- The property to check the flag for.updater- The function that updates this node.
-
shallowStructuralEquals
- Returns:
- Shallow structural equality between
firstandsecond, as defined by
structuralEquals(DirectedGraphNode)and concrete implementations. Checking structural equality of children is not intended here.
-
structuralEquals
Checks for equality with another node based on equalTo. The children are also checked recursively.
- Parameters:
other- The other node to check.visited- The list of visited nodes (prevents infinite recursion).- Returns:
- Whether this node equals other based on equalityCriteria.
-
structuralEquals
Checks for structural equality with another node based on equalityCriteria. The children are also checked recursively.
- Parameters:
other- The other node to check. Must be the same type as this node to return true.- Returns:
- Whether this node equals other based on equalityCriteria.
-
self
-
abstractSelf
-