Class Paths<C,P>

java.lang.Object
lib.aide.paths.Paths<C,P>
Type Parameters:
C - the type of the path components
P - the type of the payload
Direct Known Subclasses:
RoutesTree

public class Paths<C,P> extends Object
This class represents a hierarchical path structure that supports adding, finding, and resolving nodes within the structure. Each node can have a payload and a list of child nodes.
  • Constructor Details

    • Paths

      public Paths(@NotNull @NotNull Paths.PayloadComponentsSupplier<C,P> parser, @NotNull @NotNull Paths.NodePopulationStrategy<C,P> nodePopulate)
      Constructs a Paths object with the specified root payload and payload components supplier.
      Parameters:
      parser - the supplier for payload components
      rootPayload - the payload for the initial root node
    • Paths

      public Paths(@NotNull @NotNull Paths.PayloadComponentsSupplier<C,P> parser)
      Constructs a Paths object with the specified root payload and payload components supplier.
      Parameters:
      parser - the supplier for payload components
      rootPayload - the payload for the initial root node
  • Method Details

    • root

      public Paths<C,P>.Node root()
      Returns the root node.
      Returns:
      the root node
    • populate

      public void populate(P payload, Paths.InterimPayloadSupplier<C,P> ips)
      Populates the tree structure with the specified payload, starting from root.
      Parameters:
      payload - the payload to populate
      ips - what to do with payloads for child nodes defined before parents
    • populate

      public void populate(P payload)
      Populates the tree structure with the specified payload, starting from root with default behavior for interim payloads.
      Parameters:
      payload - the payload to populate
    • findNode

      public Optional<Paths<C,P>.Node> findNode(String fullPath)
      Finds a node in the tree structure based on the full path.
      Parameters:
      fullPath - the full path of the node to find
      Returns:
      an Optional containing the found node if exists, or an empty Optional
    • forEach

      public void forEach(Consumer<? super Paths<C,P>.Node> action, boolean depthFirst)
      Runs action for every node in the tree
      Parameters:
      action - callback to run
      depthFirst - whether to run depth-first
    • forEach

      public void forEach(Consumer<? super Paths<C,P>.Node> action)
      Runs action for every node in the tree
      Parameters:
      action - callback to run depth-first
    • deepMerge

      public static List<Map.Entry<String,Paths.DeepMergeOperation>> deepMerge(Map<String,Object> original, Map<String,Object> updates)
      Deeply merges the updates map into the original map. If both maps contain nested maps for the same key, those maps are merged recursively. Otherwise, the value from the updates map overwrites the value in the original map.
      Parameters:
      original - The original map to be updated.
      updates - The map containing updates to be merged into the original map.
      Returns:
      A list of key and MergeOperation pairs representing the changes made during the merge.