Class PropertyTree
- java.lang.Object
-
- org.opennms.netmgt.telemetry.distributed.common.PropertyTree
-
public class PropertyTree extends 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 Optional<PropertyTree.Node>
find(Iterable<String> path)
Finds the node at the given path.Optional<PropertyTree.Node>
find(String... path)
static PropertyTree
from(Dictionary<String,?> properties)
Create a newPropertyTree
from the givenDictionary
.static PropertyTree
from(Map<String,String> map)
Create a newPropertyTree
from the givenMap
.Map<String,String>
getFlatMap(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.Map<String,String>
getMap(String... path)
Get the values of all children nodes at the given path.Optional<Boolean>
getOptionalBoolean(String... path)
Get the value at the given path parsed as anBoolean
.Optional<Integer>
getOptionalInteger(String... path)
Get the value at the given path parsed as anInteger
.String
getRequiredString(String... path)
Get the value at the given path.Map<String,PropertyTree>
getSubTrees(String... path)
Get the children nodes at the given path represented as sub-trees.
-
-
-
Method Detail
-
find
public Optional<PropertyTree.Node> find(Iterable<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 Optional<PropertyTree.Node> find(String... path)
- See Also:
find(Iterable)
-
getRequiredString
public String getRequiredString(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:
NoSuchElementException
- if there is no such node or the node has no value
-
getOptionalInteger
public Optional<Integer> getOptionalInteger(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 Optional<Boolean> getOptionalBoolean(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 Map<String,String> getMap(String... path)
Get the values of all children nodes at the given path. The values are mapped by the children node names.
-
getFlatMap
public Map<String,String> getFlatMap(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.
-
getSubTrees
public Map<String,PropertyTree> getSubTrees(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.
-
from
public static PropertyTree from(Map<String,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(Dictionary<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
-
-