Interface TreeWalker<T>

Type Parameters:
T - define the TreeType
All Known Implementing Classes:
ListTree

@API(status=STABLE, since="1.0", consumers="ListTree") @Component public interface TreeWalker<T>
Implementation of the TREE data structure. The domain object TreeNode represent a node:
  • UUID (String): auto generated by constructor
  • name (String): a human readable description of the node (e. g. folder)
  • value (Object): represent the content of a node (e. g. file)
  • parent (String): reference of the UUID to the parent node
  • Since:
    1.0
    Version:
    1.2
    Author:
    elmar.dott@gmail.com
    • Field Details

      • FEATURE_ID

        @API(status=STABLE, since="1.2") static final String FEATURE_ID
        Identifier for the given feature.
        See Also:
    • Method Details

      • addRoot

        @API(status=STABLE, since="1.0") boolean addRoot(TreeNode<T> root)
        Add the root node to the tree.
        Parameters:
        root - as TreeNode
        Returns:
        true on success
      • isElementOfTree

        @API(status=STABLE, since="1.0") boolean isElementOfTree(TreeNode<T> node)
        Test if a node is a element of the tree. This function do not validate if all tree elements are well connected. This tests returns true if the element is added to the tree list.
        Parameters:
        node - as TreeNode
        Returns:
        true on success
      • isEmpty

        @API(status=STABLE, since="1.0") boolean isEmpty()
        Check if the representing tree is empty.
        Returns:
        true n success
      • isLeaf

        @API(status=STABLE, since="1.0") boolean isLeaf(TreeNode<T> node)
        Check if a given node is a leaf in the tree. Leafs don't have child nodes. => node.uuid != otherNode.getParent
        Parameters:
        node - as TreeNode
        Returns:
        true on success
      • removeNode

        @API(status=STABLE, since="1.0") boolean removeNode(TreeNode<T> node)
        Removes a Node (leaf) from the tree. This method allows just to cut elements from the tree which has no children. In the case it is necessary to cut a subtree use the prune() method.
        Parameters:
        node - as TreeNode
        Returns:
        true on success
      • countNodes

        @API(status=STABLE, since="1.0") int countNodes()
        Count the nodes of the tree.
        Returns:
        count as int
      • isNameUnique

        @API(status=STABLE, since="1.0") int isNameUnique(String nodeName)
        Test if a element name exist more than one time. Useful to get to know how often a name is used. Return the count how often the name for this element already appear in the data structure.
        Parameters:
        nodeName - as String
        Returns:
        count as int
      • getElementByName

        @API(status=STABLE, since="1.0") List<TreeNode<T>> getElementByName(String nodeName)
        Get all nodes of the tree with the same NodeName.
        Parameters:
        nodeName - as String
        Returns:
        nodes as List
      • getLeafs

        @API(status=STABLE, since="1.0") List<TreeNode<T>> getLeafs()
        Get all leaf nodes of the tree.
        Returns:
        leafs as List
      • getTree

        @API(status=STABLE, since="1.0") List<TreeNode<T>> getTree()
        Get the full tree.
        Returns:
        tree as List
      • getNodeByUuid

        @API(status=STABLE, since="1.0") TreeNode<T> getNodeByUuid(String uuid)
        Get a TreeNode by his UUID.
        Parameters:
        uuid - as String
        Returns:
        node as TreeNode
      • getRoot

        @API(status=STABLE, since="3.0") TreeNode<T> getRoot()
        Get the root TreeNode. If no root is set the return will be NULL.
        Returns:
        root as TreeNode
      • addNode

        @API(status=STABLE, since="1.0") boolean addNode(TreeNode<T> node)
        Add the node to the tree. Check if the node is already exist in the tree by comparing the UUID. In the case there exist a node already with the UUID then the new one will not added. Another check is that not exist two nodes with the same name and the same parent. Also for this case the node will not be added to the tree.
        Parameters:
        node - as TreeNode
        Returns:
        true on success
      • clear

        @API(status=STABLE, since="1.0") void clear()
        Reset all internal data of the TreeWalker.
      • prune

        @API(status=STABLE, since="1.0") void prune(TreeNode<T> cutNode) throws MisconfigurationException
        Remove an element and all his child nodes from the tree.
        Parameters:
        cutNode - as TreeNode
        Throws:
        MisconfigurationException
      • merge

        @API(status=STABLE, since="1.0") void merge(String parentUuid, TreeWalker<T> appendingTree)
        Merge another Tree (TreeWalker) into the present tree. After choosing a node from the present tree the whole new three (including) the ROOT element will apped on the chosen merge node.
        Parameters:
        parentUuid - as String
        appendingTree - as TreeWalker
      • validateTree

        @API(status=STABLE, since="2.1") boolean validateTree(List<TreeNode<T>> tree) throws MisconfigurationException
        Check if the tree is valid. A valid tree has no "unconnected" elements (treeNodes). There are three failure types:
      • 1: Single TreeNode elements without a parent
      • 2: Connected TreeNode fragments without a root
      • 3: Multiple Trees with root element
      • Those three types can occur in various combinations.
        Parameters:
        tree - as List
        Returns:
        true on success
        Throws:
        MisconfigurationException