Class ListTree<T>

java.lang.Object
org.europa.together.application.ListTree<T>
Type Parameters:
T - define the TreeType
All Implemented Interfaces:
TreeWalker<T>

@Repository public class ListTree<T> extends Object implements TreeWalker<T>
Implementation of a TreeWalker.
  • Constructor Details

    • ListTree

      public ListTree()
      Constructor.
    • ListTree

      public ListTree(TreeNode<T> root)
      Constructor.
      Parameters:
      root - as TreeNode
  • Method Details

    • addRoot

      public boolean addRoot(TreeNode<T> root)
      Description copied from interface: TreeWalker
      Add the root node to the tree.
      Specified by:
      addRoot in interface TreeWalker<T>
      Parameters:
      root - as TreeNode
      Returns:
      true on success
    • isElementOfTree

      public boolean isElementOfTree(TreeNode<T> node)
      Description copied from interface: TreeWalker
      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.
      Specified by:
      isElementOfTree in interface TreeWalker<T>
      Parameters:
      node - as TreeNode
      Returns:
      true on success
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: TreeWalker
      Check if the representing tree is empty.
      Specified by:
      isEmpty in interface TreeWalker<T>
      Returns:
      true n success
    • isLeaf

      public boolean isLeaf(TreeNode<T> leaf)
      Description copied from interface: TreeWalker
      Check if a given node is a leaf in the tree. Leafs don't have child nodes. => node.uuid != otherNode.getParent
      Specified by:
      isLeaf in interface TreeWalker<T>
      Parameters:
      leaf - as TreeNode
      Returns:
      true on success
    • removeNode

      public boolean removeNode(TreeNode<T> node)
      Description copied from interface: TreeWalker
      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.
      Specified by:
      removeNode in interface TreeWalker<T>
      Parameters:
      node - as TreeNode
      Returns:
      true on success
    • countNodes

      public int countNodes()
      Description copied from interface: TreeWalker
      Count the nodes of the tree.
      Specified by:
      countNodes in interface TreeWalker<T>
      Returns:
      count as int
    • isNameUnique

      public int isNameUnique(String nodeName)
      Description copied from interface: TreeWalker
      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.
      Specified by:
      isNameUnique in interface TreeWalker<T>
      Parameters:
      nodeName - as String
      Returns:
      count as int
    • getElementByName

      public List<TreeNode<T>> getElementByName(String nodeName)
      Description copied from interface: TreeWalker
      Get all nodes of the tree with the same NodeName.
      Specified by:
      getElementByName in interface TreeWalker<T>
      Parameters:
      nodeName - as String
      Returns:
      nodes as List
    • getLeafs

      public List<TreeNode<T>> getLeafs()
      Description copied from interface: TreeWalker
      Get all leaf nodes of the tree.
      Specified by:
      getLeafs in interface TreeWalker<T>
      Returns:
      leafs as List
    • getTree

      public List<TreeNode<T>> getTree()
      Description copied from interface: TreeWalker
      Get the full tree.
      Specified by:
      getTree in interface TreeWalker<T>
      Returns:
      tree as List
    • getNodeByUuid

      public TreeNode<T> getNodeByUuid(String uuid)
      Description copied from interface: TreeWalker
      Get a TreeNode by his UUID.
      Specified by:
      getNodeByUuid in interface TreeWalker<T>
      Parameters:
      uuid - as String
      Returns:
      node as TreeNode
    • getRoot

      public TreeNode<T> getRoot()
      Description copied from interface: TreeWalker
      Get the root TreeNode. If no root is set the return will be NULL.
      Specified by:
      getRoot in interface TreeWalker<T>
      Returns:
      root as TreeNode
    • addNode

      public boolean addNode(TreeNode<T> node)
      Description copied from interface: TreeWalker
      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.
      Specified by:
      addNode in interface TreeWalker<T>
      Parameters:
      node - as TreeNode
      Returns:
      true on success
    • clear

      public void clear()
      Description copied from interface: TreeWalker
      Reset all internal data of the TreeWalker.
      Specified by:
      clear in interface TreeWalker<T>
    • prune

      public void prune(TreeNode<T> cutNode) throws MisconfigurationException
      Description copied from interface: TreeWalker
      Remove an element and all his child nodes from the tree.
      Specified by:
      prune in interface TreeWalker<T>
      Parameters:
      cutNode - as TreeNode
      Throws:
      MisconfigurationException
    • merge

      public void merge(String parentUuid, TreeWalker<T> appendingTree)
      Description copied from interface: TreeWalker
      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.
      Specified by:
      merge in interface TreeWalker<T>
      Parameters:
      parentUuid - as String
      appendingTree - as TreeWalker
    • validateTree

      public boolean validateTree(List<TreeNode<T>> collection) throws MisconfigurationException
      Description copied from interface: TreeWalker
      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.
      Specified by:
      validateTree in interface TreeWalker<T>
      Parameters:
      collection - as List
      Returns:
      true on success
      Throws:
      MisconfigurationException
    • toString

      public String toString()
      Overrides:
      toString in class Object