Class PropertyTree
- java.lang.Object
-
- org.opennms.netmgt.telemetry.distributed.common.PropertyTree
-
public class PropertyTree extends java.lang.Object
A 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 class
PropertyTree.Node
The 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 PropertyTree
from(java.util.Dictionary<java.lang.String,?> properties)
Create a newPropertyTree
from the givenDictionary
.static PropertyTree
from(java.util.Map<java.lang.String,java.lang.String> map)
Create a newPropertyTree
from 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.String
getRequiredString(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.Node
if 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
Integer
value 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
Integer
value 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
Map
from 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
Map
from 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 resultingMap
will contain an entry for each children of the addressed node. The name of the children will be used as key. The value will be newPropertyTree
instance 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
Map
from 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 newPropertyTree
from 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
PropertyTree
instance
-
from
public static PropertyTree from(java.util.Dictionary<java.lang.String,?> properties)
Create a newPropertyTree
from 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
PropertyTree
instance
-
-