Package org.europa.together.business
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
- 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 Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdd the node to the tree.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.booleanvalidateTree(List<TreeNode<T>> tree) Check if the tree is valid.
-
Field Details
-
FEATURE_ID
Identifier for the given feature.- See Also:
-
-
Method Details
-
addRoot
Add the root node to the tree.- Parameters:
root- as TreeNode- Returns:
- true on success
-
isElementOfTree
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
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
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
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
Get all nodes of the tree with the same NodeName.- Parameters:
nodeName- as String- Returns:
- nodes as List
-
getLeafs
Get all leaf nodes of the tree.- Returns:
- leafs as List
-
getTree
Get the full tree.- Returns:
- tree as List
-
getNodeByUuid
Get a TreeNode by his UUID.- Parameters:
uuid- as String- Returns:
- node as TreeNode
-
getRoot
Get the root TreeNode. If no root is set the return will be NULL.- Returns:
- root as TreeNode
-
addNode
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
Remove an element and all his child nodes from the tree.- Parameters:
cutNode- as TreeNode- Throws:
MisconfigurationException- case of error
-
merge
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 StringappendingTree- 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- case of error
-