Class LocationTree<D,T>
- Type Parameters:
D- the type of document identifiersT- the type of subjects
- All Implemented Interfaces:
Locatable<D>
Objects of this class hold an arbitrary number of subjects, their locations and parameters, as well as hierarchical relationships among them. This information is suitable to track the genealogy of complex aggregate object structures, where components may hail from different contexts; e.g., the parts of a distributed document, or various call sites using an embedded domain-specific language.
Proper subtrees (i.e., other objects of this class) are organized in a local tree structure composed from leaves and branches. Leaves hold a proper subtree each. In a branch, there may be arbitrarily many alternatives which are distinguished by a label string. Labels should be valid Java identifiers. Every leaf is addressed uniquely by a sequence of zero or more label identifiers.
Additionally to subtrees, each tree root may hold a string-indexed map of parameter values. The keys should be valid Java identifiers. Parameters values may be arbitrary objects. They need not be distinct from the subjects of a tree by nature. However, most parameter values are likely simple data: wrapper objects for primitive values or strings.
- Since:
- 1.1
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for a subtree structure.static interfaceInterface of local tree nodes. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Consumer<T> empty()Returns a functional object that does nothing.Map<String, LocationTree<D, T>> Returns a flat map of the proper subtrees of this tree.Returns the root location of this tree if available.Returns the main description of this tree.getRoot()Returns the root node of this tree.Returns the root subject of this tree if available.static <D,T> LocationTree <D, T> Returns a new tree without proper subtrees.static <D,T> LocationTree <D, T> of(String mainDescription, @Opt Location<D> location, T subject, Consumer<? super Collections.MapBuilder<String, Object>> parameters, Consumer<? super LocationTree.Builder<D, T>> branching) Returns a new tree with parameters and some proper subtrees.static <D,T> LocationTree <D, T> of(String mainDescription, @Opt Location<D> location, T subject, Consumer<? super Collections.MapBuilder<String, Object>> parameters, Supplier<LocationTree<D, T>> content) Returns a new tree with parameters and a single unlabeled proper subtree.static <D,T> LocationTree <D, T> of(String mainDescription, @Opt Location<D> location, T subject, Supplier<LocationTree<D, T>> content) Returns a new tree with a single unlabeled proper subtree.Returns the map of root parameters of this tree.toString()
-
Field Details
-
PATH_SEPARATOR
The string used to separate path elements.- See Also:
-
-
Method Details
-
toString
-
getMainDescription
Returns the main description of this tree.The main description should describe the root subject and/or the whole aggregate in a user-friendly way.
- Returns:
- the main description of this tree
-
getLocation
Returns the root location of this tree if available.- Specified by:
getLocationin interfaceLocatable<D>- Returns:
- the root location of this tree, or
nullif not available
-
getSubject
Returns the root subject of this tree if available.- Returns:
- the root subject of this tree, or
nullif not available
-
parameters
Returns the map of root parameters of this tree.The returned map should be treated as immutable. The caller should not attempt to modify its content, but may assume that the content does not change concurrently either.
- Returns:
- the map of root parameters of this tree
-
getRoot
Returns the root node of this tree.- Returns:
- the root node of this tree
-
flatContent
Returns a flat map of the proper subtrees of this tree.The returned map should be treated as immutable. The caller should not attempt to modify its content, but may assume that the content does not change concurrently either.
- Returns:
- a flat map of the subtrees of this tree
-
of
public static <D,T> LocationTree<D,T> of(String mainDescription, @Opt Location<D> location, @Opt T subject) Returns a new tree without proper subtrees.- Type Parameters:
D- the type of document identifiersT- the type of subjects- Parameters:
mainDescription- the main description of the new treelocation- the root location of the new tree, ornullif not availablesubject- the root subject of the new tree, ornullif not available- Returns:
- a new leaf
- Throws:
NullPointerException- ifmainDescriptionis null
-
of
public static <D,T> LocationTree<D,T> of(String mainDescription, @Opt Location<D> location, T subject, Supplier<LocationTree<D, T>> content) Returns a new tree with a single unlabeled proper subtree.The subtree will be computed lazily on demand after this method has returned.
- Type Parameters:
D- the type of document identifiersT- the type of subjects- Parameters:
mainDescription- the main description of the new treelocation- the root location of the new tree, ornullif not availablesubject- the root subject of the new tree, ornullif not availablecontent- a functional object that provides the subtree- Returns:
- a new tree
- Throws:
NullPointerException- ifmainDescriptionorcontentis null
-
of
public static <D,T> LocationTree<D,T> of(String mainDescription, @Opt Location<D> location, T subject, Consumer<? super Collections.MapBuilder<String, Object>> parameters, Supplier<LocationTree<D, T>> content) Returns a new tree with parameters and a single unlabeled proper subtree.The subtree will be computed lazily on demand after this method has returned.
- Type Parameters:
D- the type of document identifiersT- the type of subjects- Parameters:
mainDescription- the main description of the new treelocation- the root location of the new tree, ornullif not availablesubject- the root subject of the new tree, ornullif not availableparameters- a functional object that populates a map builder with parameter entriescontent- a functional object that provides the subtree- Returns:
- a new tree
- Throws:
NullPointerException- ifmainDescription,parametersorcontentis null
-
of
public static <D,T> LocationTree<D,T> of(String mainDescription, @Opt Location<D> location, T subject, Consumer<? super Collections.MapBuilder<String, Object>> parameters, Consumer<? super LocationTree.Builder<D, T>> branching) Returns a new tree with parameters and some proper subtrees.- Type Parameters:
D- the type of document identifiersT- the type of subjects- Parameters:
mainDescription- the main description of the new treelocation- the root location of the new tree, ornullif not availablesubject- the root subject of the new tree, ornullif not availableparameters- a functional object that populates a map builder with parameter entriesbranching- a functional object that populates the subtrees- Returns:
- a new tree
- Throws:
NullPointerException- ifmainDescription,parametersorbranchingis null
-
empty
Returns a functional object that does nothing.The resulting object is useful to populate a map builder with no entries.
- Type Parameters:
T- the type of objects to consume while doing nothing- Returns:
- a functional object that does nothing
-