Class 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.
    • 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 new PropertyTree from the given Dictionary.
      static PropertyTree from​(java.util.Map<java.lang.String,​java.lang.String> map)
      Create a new PropertyTree from the given Map.
      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 an Boolean.
      java.util.Optional<java.lang.Integer> getOptionalInteger​(java.lang.String... path)
      Get the value at the given path parsed as an Integer.
      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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 an Optional.empty() value if one of the nodes in the path does not exist
      • 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 an Integer.
        Parameters:
        path - the path of the node to return split into its elements
        Returns:
        the Integer value of the node at the given path or Optional.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 an Boolean.
        Parameters:
        path - the path of the node to return split into its elements
        Returns:
        the Integer value of the node at the given path or Optional.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 empty Map
      • 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 empty Map
      • 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 resulting Map 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 new PropertyTree 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 empty Map
      • from

        public static PropertyTree from​(java.util.Map<java.lang.String,​java.lang.String> map)
        Create a new PropertyTree from the given Map. 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 new PropertyTree from the given Dictionary. 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