Interface DirectedGraphNode<P extends Enum<?>,A extends DirectedGraphNode<P,A,?>,T extends DirectedGraphNode<P,A,T>>

Type Parameters:
P - Property Type
A - Abstract Type that all nodes will have
T - 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

public interface DirectedGraphNode<P extends Enum<?>,A extends DirectedGraphNode<P,A,?>,T extends DirectedGraphNode<P,A,T>>
Provides a mechanism for working with nodes in a directed graph. Uses a recursive structure to simplify attaching nodes as "children."

This class is not Thread-Safe.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static enum 
    Specifies behavior for updating a property of this node.
  • Method Summary

    Modifier and Type
    Method
    Description
    default A
     
    default boolean
    Traverses through every node accessible from this node and returns true if one of the nodes is null.
    default boolean
    Traverses through every node accessible from this node and returns true if one of the nodes is null.
    default A
    dfs(Function<A,Boolean> criteria)
    Executes a DFS on self and all accessible children of the graph.
    default A
    dfs(Function<A,Boolean> criteria, Set<A> visited)
    Executes a DFS on self and all accessible children of the graph.
    default void
    forEach(Consumer<A> function)
    Executes the Consumer on self and every accessible node of the graph.
    default void
    forEachChild(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.
    Get the Class<T> type of the current Node
    default T
     
    boolean
    shallowStructuralEquals(T first, T second)
     
    default boolean
    Checks for structural equality with another node based on equalityCriteria.
    default boolean
    structuralEquals(A other, Set<A> visited)
    Checks for equality with another node based on equalTo.
    default void
    updateProperty(P property, Consumer<A> updater)
    Updates this node based on the flag of a property.
    default void
    updateProperty(P property, Consumer<A> updater, Set<A> visited)
    Updates this node based on the flag of a property.
  • Method Details

    • getChildren

      List<A> 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 to updateProperty.
    • getType

      Class<T> getType()
      Get the Class<T> type of the current Node
    • dfs

      default A dfs(Function<A,Boolean> criteria)
      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

      default A dfs(Function<A,Boolean> criteria, Set<A> visited)
      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 returned
      visited - 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

      default void forEach(Consumer<A> function)
      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

      default void forEachChild(Consumer<A> function)
      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

      default boolean containsNullNode(Set<A> visited)
      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

      default void updateProperty(P property, Consumer<A> updater, Set<A> visited)

      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

      default void updateProperty(P property, Consumer<A> updater)

      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

      boolean shallowStructuralEquals(T first, T second)
      Returns:
      Shallow structural equality between first and second, as defined by
      structuralEquals(DirectedGraphNode) and concrete implementations. Checking structural equality of children is not intended here.
    • structuralEquals

      default boolean structuralEquals(A other, Set<A> visited)

      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

      default boolean structuralEquals(A other)

      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

      default T self()
    • abstractSelf

      default A abstractSelf()