Package org.europa.together.application
Class ListTree<T>
java.lang.Object
org.europa.together.application.ListTree<T>
- Type Parameters:
T
- define the TreeType
- All Implemented Interfaces:
TreeWalker<T>
Implementation of a TreeWalker.
-
Field Summary
Fields inherited from interface org.europa.together.business.TreeWalker
FEATURE_ID
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Add the node to the tree.boolean
Add the root node to the tree.void
clear()
Reset all internal data of the TreeWalker.int
Count the nodes of the tree.getElementByName
(String nodeName) Get all nodes of the tree with the same NodeName.getLeafs()
Get all leaf nodes of the tree.getNodeByUuid
(String uuid) Get a TreeNode by his UUID.getRoot()
Get the root TreeNode.getTree()
Get the full tree.boolean
isElementOfTree
(TreeNode<T> node) Test if a node is a element of the tree.boolean
isEmpty()
Check if the representing tree is empty.boolean
Check if a given node is a leaf in the tree.int
isNameUnique
(String nodeName) Test if a element name exist more than one time.void
merge
(String parentUuid, TreeWalker<T> appendingTree) Merge another Tree (TreeWalker) into the present tree.void
Remove an element and all his child nodes from the tree.boolean
removeNode
(TreeNode<T> node) Removes a Node (leaf) from the tree.toString()
boolean
validateTree
(List<TreeNode<T>> collection) Check if the tree is valid.
-
Constructor Details
-
ListTree
public ListTree()Constructor. -
ListTree
Constructor.- Parameters:
root
- as TreeNode
-
-
Method Details
-
addRoot
Description copied from interface:TreeWalker
Add the root node to the tree.- Specified by:
addRoot
in interfaceTreeWalker<T>
- Parameters:
root
- as TreeNode- Returns:
- true on success
-
isElementOfTree
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 interfaceTreeWalker<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 interfaceTreeWalker<T>
- Returns:
- true n success
-
isLeaf
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 interfaceTreeWalker<T>
- Parameters:
leaf
- as TreeNode- Returns:
- true on success
-
removeNode
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 interfaceTreeWalker<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 interfaceTreeWalker<T>
- Returns:
- count as int
-
isNameUnique
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 interfaceTreeWalker<T>
- Parameters:
nodeName
- as String- Returns:
- count as int
-
getElementByName
Description copied from interface:TreeWalker
Get all nodes of the tree with the same NodeName.- Specified by:
getElementByName
in interfaceTreeWalker<T>
- Parameters:
nodeName
- as String- Returns:
- nodes as List
-
getLeafs
Description copied from interface:TreeWalker
Get all leaf nodes of the tree.- Specified by:
getLeafs
in interfaceTreeWalker<T>
- Returns:
- leafs as List
-
getTree
Description copied from interface:TreeWalker
Get the full tree.- Specified by:
getTree
in interfaceTreeWalker<T>
- Returns:
- tree as List
-
getNodeByUuid
Description copied from interface:TreeWalker
Get a TreeNode by his UUID.- Specified by:
getNodeByUuid
in interfaceTreeWalker<T>
- Parameters:
uuid
- as String- Returns:
- node as TreeNode
-
getRoot
Description copied from interface:TreeWalker
Get the root TreeNode. If no root is set the return will be NULL.- Specified by:
getRoot
in interfaceTreeWalker<T>
- Returns:
- root as TreeNode
-
addNode
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 interfaceTreeWalker<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 interfaceTreeWalker<T>
-
prune
Description copied from interface:TreeWalker
Remove an element and all his child nodes from the tree.- Specified by:
prune
in interfaceTreeWalker<T>
- Parameters:
cutNode
- as TreeNode- Throws:
MisconfigurationException
-
merge
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 interfaceTreeWalker<T>
- Parameters:
parentUuid
- as StringappendingTree
- as TreeWalker
-
validateTree
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 interfaceTreeWalker<T>
- Parameters:
collection
- as List- Returns:
- true on success
- Throws:
MisconfigurationException
-
toString
-