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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdd the node to the tree.final booleanAdd the root node to the tree.voidclear()Reset all internal data of the TreeWalker.intCount 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.booleanisElementOfTree(TreeNode<T> node) Test if a node is a element of the tree.booleanisEmpty()Check if the representing tree is empty.booleanCheck if a given node is a leaf in the tree.intisNameUnique(String nodeName) Test if a element name exist more than one time.voidmerge(String parentUuid, TreeWalker<T> appendingTree) Merge another Tree (TreeWalker) into the present tree.voidRemove an element and all his child nodes from the tree.booleanremoveNode(TreeNode<T> node) Removes a Node (leaf) from the tree.toString()booleanvalidateTree(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:TreeWalkerAdd the root node to the tree.- Specified by:
addRootin interfaceTreeWalker<T>- Parameters:
root- as TreeNode- Returns:
- true on success
-
isElementOfTree
Description copied from interface:TreeWalkerTest 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:
isElementOfTreein interfaceTreeWalker<T>- Parameters:
node- as TreeNode- Returns:
- true on success
-
isEmpty
public boolean isEmpty()Description copied from interface:TreeWalkerCheck if the representing tree is empty.- Specified by:
isEmptyin interfaceTreeWalker<T>- Returns:
- true n success
-
isLeaf
Description copied from interface:TreeWalkerCheck if a given node is a leaf in the tree. Leafs don't have child nodes. => node.uuid != otherNode.getParent- Specified by:
isLeafin interfaceTreeWalker<T>- Parameters:
leaf- as TreeNode- Returns:
- true on success
-
removeNode
Description copied from interface:TreeWalkerRemoves 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:
removeNodein interfaceTreeWalker<T>- Parameters:
node- as TreeNode- Returns:
- true on success
-
countNodes
public int countNodes()Description copied from interface:TreeWalkerCount the nodes of the tree.- Specified by:
countNodesin interfaceTreeWalker<T>- Returns:
- count as int
-
isNameUnique
Description copied from interface:TreeWalkerTest 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:
isNameUniquein interfaceTreeWalker<T>- Parameters:
nodeName- as String- Returns:
- count as int
-
getElementByName
Description copied from interface:TreeWalkerGet all nodes of the tree with the same NodeName.- Specified by:
getElementByNamein interfaceTreeWalker<T>- Parameters:
nodeName- as String- Returns:
- nodes as List
-
getLeafs
Description copied from interface:TreeWalkerGet all leaf nodes of the tree.- Specified by:
getLeafsin interfaceTreeWalker<T>- Returns:
- leafs as List
-
getTree
Description copied from interface:TreeWalkerGet the full tree.- Specified by:
getTreein interfaceTreeWalker<T>- Returns:
- tree as List
-
getNodeByUuid
Description copied from interface:TreeWalkerGet a TreeNode by his UUID.- Specified by:
getNodeByUuidin interfaceTreeWalker<T>- Parameters:
uuid- as String- Returns:
- node as TreeNode
-
getRoot
Description copied from interface:TreeWalkerGet the root TreeNode. If no root is set the return will be NULL.- Specified by:
getRootin interfaceTreeWalker<T>- Returns:
- root as TreeNode
-
addNode
Description copied from interface:TreeWalkerAdd 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:
addNodein interfaceTreeWalker<T>- Parameters:
node- as TreeNode- Returns:
- true on success
-
clear
public void clear()Description copied from interface:TreeWalkerReset all internal data of the TreeWalker.- Specified by:
clearin interfaceTreeWalker<T>
-
prune
Description copied from interface:TreeWalkerRemove an element and all his child nodes from the tree.- Specified by:
prunein interfaceTreeWalker<T>- Parameters:
cutNode- as TreeNode- Throws:
MisconfigurationException- case of error
-
merge
Description copied from interface:TreeWalkerMerge 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:
mergein interfaceTreeWalker<T>- Parameters:
parentUuid- as StringappendingTree- as TreeWalker
-
validateTree
Description copied from interface:TreeWalkerCheck 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:
validateTreein interfaceTreeWalker<T>- Parameters:
collection- as List- Returns:
- true on success
- Throws:
MisconfigurationException- case of error
-
toString
-