Package lib.aide.paths
Class Paths<C,P>
java.lang.Object
lib.aide.paths.Paths<C,P>
- Type Parameters:
C
- the type of the path componentsP
- the type of the payload
- Direct Known Subclasses:
RoutesTree
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Enum to represent the type of merge operation performed.static interface
class
Represents a node in the hierarchical path structure.static interface
static interface
Interface defining methods to supply and assemble path components. -
Constructor Summary
ConstructorsConstructorDescriptionPaths
(@NotNull Paths.PayloadComponentsSupplier<C, P> parser) Constructs a Paths object with the specified root payload and payload components supplier.Paths
(@NotNull Paths.PayloadComponentsSupplier<C, P> parser, @NotNull Paths.NodePopulationStrategy<C, P> nodePopulate) Constructs a Paths object with the specified root payload and payload components supplier. -
Method Summary
Modifier and TypeMethodDescriptionstatic List
<Map.Entry<String, Paths.DeepMergeOperation>> Deeply merges the updates map into the original map.Finds a node in the tree structure based on the full path.void
Runs action for every node in the treevoid
Runs action for every node in the treevoid
Populates the tree structure with the specified payload, starting from root with default behavior for interim payloads.void
populate
(P payload, Paths.InterimPayloadSupplier<C, P> ips) Populates the tree structure with the specified payload, starting from root.root()
Returns the root node.
-
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 componentsrootPayload
- the payload for the initial root node
-
Paths
Constructs a Paths object with the specified root payload and payload components supplier.- Parameters:
parser
- the supplier for payload componentsrootPayload
- the payload for the initial root node
-
-
Method Details
-
root
Returns the root node.- Returns:
- the root node
-
populate
Populates the tree structure with the specified payload, starting from root.- Parameters:
payload
- the payload to populateips
- what to do with payloads for child nodes defined before parents
-
populate
Populates the tree structure with the specified payload, starting from root with default behavior for interim payloads.- Parameters:
payload
- the payload to populate
-
findNode
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
Runs action for every node in the tree- Parameters:
action
- callback to rundepthFirst
- whether to run depth-first
-
forEach
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.
-