Class PropertyTree
- java.lang.Object
-
- org.opennms.netmgt.telemetry.distributed.common.PropertyTree
-
public class PropertyTree extends java.lang.ObjectA tree representation for dot-separated properties. The tree consists of nodes, where each node can have a value. Each node can have an arbitrary number of child nodes which are addressed by the node name.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPropertyTree.NodeThe node of thePropertyTree.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Optional<PropertyTree.Node>find(java.lang.Iterable<java.lang.String> path)Finds the node at the given path.java.util.Optional<PropertyTree.Node>find(java.lang.String... path)static PropertyTreefrom(java.util.Dictionary<java.lang.String,?> properties)Create a newPropertyTreefrom the givenDictionary.static PropertyTreefrom(java.util.Map<java.lang.String,java.lang.String> map)Create a newPropertyTreefrom the givenMap.java.util.Map<java.lang.String,java.lang.String>getFlatMap(java.lang.String... path)Get the values of all child nodes at the given path, enumerating any subtrees and converting their paths into dot-separated property names.java.util.Map<java.lang.String,java.lang.String>getMap(java.lang.String... path)Get the values of all children nodes at the given path.java.util.Optional<java.lang.Boolean>getOptionalBoolean(java.lang.String... path)Get the value at the given path parsed as anBoolean.java.util.Optional<java.lang.Integer>getOptionalInteger(java.lang.String... path)Get the value at the given path parsed as anInteger.java.lang.StringgetRequiredString(java.lang.String... path)Get the value at the given path.java.util.Map<java.lang.String,PropertyTree>getSubTrees(java.lang.String... path)Get the children nodes at the given path represented as sub-trees.
-
-
-
Method Detail
-
find
public java.util.Optional<PropertyTree.Node> find(java.lang.Iterable<java.lang.String> path)
Finds the node at the given path.- Parameters:
path- the path of the node to return split into its elements- Returns:
- the
PropertyTree.Nodeif there is a node on the given path or anOptional.empty()value if one of the nodes in the path does not exist
-
find
public java.util.Optional<PropertyTree.Node> find(java.lang.String... path)
- See Also:
find(Iterable)
-
getRequiredString
public java.lang.String getRequiredString(java.lang.String... path)
Get the value at the given path. The node is required to exist.- Parameters:
path- the path of the node to return split into its elements- Returns:
- the value of the node at the given path
- Throws:
java.util.NoSuchElementException- if there is no such node or the node has no value
-
getOptionalInteger
public java.util.Optional<java.lang.Integer> getOptionalInteger(java.lang.String... path)
Get the value at the given path parsed as anInteger.- Parameters:
path- the path of the node to return split into its elements- Returns:
- the
Integervalue of the node at the given path orOptional.empty()if one of the nodes in the path does not exist
-
getOptionalBoolean
public java.util.Optional<java.lang.Boolean> getOptionalBoolean(java.lang.String... path)
Get the value at the given path parsed as anBoolean.- Parameters:
path- the path of the node to return split into its elements- Returns:
- the
Integervalue of the node at the given path orOptional.empty()if one of the nodes in the path does not exist
-
getMap
public java.util.Map<java.lang.String,java.lang.String> getMap(java.lang.String... path)
Get the values of all children nodes at the given path. The values are mapped by the children node names.- Parameters:
path- the path of the node to return split into its elements- Returns:
- the
Mapfrom the children node names to its values. If one of the nodes in the path does not exist this will return an emptyMap
-
getFlatMap
public java.util.Map<java.lang.String,java.lang.String> getFlatMap(java.lang.String... path)
Get the values of all child nodes at the given path, enumerating any subtrees and converting their paths into dot-separated property names. This is intended to handle parameter keys containing dots - see NMS-12738.- Parameters:
path- the path of the node to return split into its elements- Returns:
- the
Mapfrom the children node names to its values. If one of the nodes in the path does not exist this will return an emptyMap
-
getSubTrees
public java.util.Map<java.lang.String,PropertyTree> getSubTrees(java.lang.String... path)
Get the children nodes at the given path represented as sub-trees. The sub-trees are mapped by the children node names. The resultingMapwill contain an entry for each children of the addressed node. The name of the children will be used as key. The value will be newPropertyTreeinstance in which the children node is used as root node.- Parameters:
path- the path of the node to return split into its elements- Returns:
- the
Mapfrom the children node names to its representations as sub-trees. If one of the nodes in the path does not exist this will return an emptyMap
-
from
public static PropertyTree from(java.util.Map<java.lang.String,java.lang.String> map)
Create a newPropertyTreefrom the givenMap. The keys of the map are handled as full-qualified dot-separated paths.- Parameters:
map- the path / value mapping used to create the property tree- Returns:
- a new
PropertyTreeinstance
-
from
public static PropertyTree from(java.util.Dictionary<java.lang.String,?> properties)
Create a newPropertyTreefrom the givenDictionary. The keys of the properties are handled as full-qualified dot-separated paths.- Parameters:
properties- the path / value mapping used to create the property tree- Returns:
- a new
PropertyTreeinstance
-
-