Class TreeNode<T extends YamlLine<T>>

  • Type Parameters:
    T - child nodes type
    All Implemented Interfaces:
    LineNumberAware
    Direct Known Subclasses:
    TreeRoot, YamlLine

    public abstract class TreeNode<T extends YamlLine<T>>
    extends java.lang.Object
    implements LineNumberAware
    Universal tree-like structure. Required to unify both yaml lines tree and object, containing root nodes.
    Since:
    11.05.2021
    • Constructor Summary

      Constructors 
      Constructor Description
      TreeNode​(T root)  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(T node)
      Properly attached node into this node (removing node from previous root).
      void addAll​(java.lang.Iterable<T> nodes)
      Attaches provided nodes to current.
      abstract T find​(java.lang.String path)
      Search for yaml node by path.
      java.util.List<T> getChildren()  
      T getRoot()  
      java.util.Map<java.lang.String,​T> getRootProperties()
      Note there might be comment-only nodes in case of comments parser and these are not included.
      abstract java.util.List<T> getTreeLeaves()  
      abstract java.lang.String getYamlPath()
      Note, for list items possible empty dash line is ignored (not a level in path).
      abstract java.lang.String getYamlPathElement()
      Cases: - for property or object (or list) root: "name" - for list item: "[n]" (where n number from 0).
      boolean hasChildren()  
      boolean hasListValue()  
      void setRoot​(T root)
      Change node root.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • TreeNode

        public TreeNode​(T root)
    • Method Detail

      • getRoot

        public T getRoot()
        Returns:
        root node or nul
      • setRoot

        public void setRoot​(T root)
        Change node root. Required for merging when nodes from new file must be included into old file tree.
        Parameters:
        root - new root node
      • getChildren

        public java.util.List<T> getChildren()
        Returns:
        children nodes
      • getRootProperties

        public java.util.Map<java.lang.String,​T> getRootProperties()
        Note there might be comment-only nodes in case of comments parser and these are not included.
        Returns:
        map of root properties (preserving order)
      • hasChildren

        public boolean hasChildren()
        Returns:
        true if has children
      • hasListValue

        public boolean hasListValue()
        Returns:
        true if contains list values as children (list property)
      • add

        public void add​(T node)
        Properly attached node into this node (removing node from previous root).
        Parameters:
        node - node to add as child
      • addAll

        public void addAll​(java.lang.Iterable<T> nodes)
        Attaches provided nodes to current.
        Parameters:
        nodes - nodes to add as child
      • getYamlPath

        public abstract java.lang.String getYamlPath()
        Note, for list items possible empty dash line is ignored (not a level in path).
        Returns:
        property path in yaml structure (like prop1/prop2[3]/sub) or null for tree root
      • getYamlPathElement

        public abstract java.lang.String getYamlPathElement()
        Cases: - for property or object (or list) root: "name" - for list item: "[n]" (where n number from 0). Note that scalar value will be contained in the same node and for object item it would be "empty" wrapper containing object properties as children. - for comment only node: empty string (no identity)
        Returns:
        yaml path element represented by this node.
      • getTreeLeaves

        public abstract java.util.List<T> getTreeLeaves()
        Returns:
        all scalar properties and properties with list values (not looking inside list values!)
      • find

        public abstract T find​(java.lang.String path)
        Search for yaml node by path. For list items path should include exact item number (e.g. list[1]), wildcard search not supported.

        IMPORTANT: path must NOT include node itself (node from where search started)

        Parameters:
        path - yaml path (with '/' as separator)
        Returns:
        found node or null