1. Project Clover database Wed Jan 17 2024 23:40:18 CST
  2. Package org.europa.together.business

File TreeWalker.java

 

Code metrics

0
0
0
1
197
47
0
-
-
0
-

Classes

Class Line # Actions
TreeWalker 26 0 - 0 0
-1.0 -
 

Contributing tests

No tests hitting this source file were found.

Source view

1    package org.europa.together.business;
2   
3    import java.util.List;
4    import org.apiguardian.api.API;
5    import static org.apiguardian.api.API.Status.STABLE;
6    import org.europa.together.domain.TreeNode;
7    import org.europa.together.exceptions.MisconfigurationException;
8    import org.springframework.stereotype.Component;
9   
10    /**
11    * Implementation of the TREE data structure. The domain object TreeNode
12    * represent a node: <br>
13    * <li>UUID (String): auto generated by constructor
14    * <li>name (String): a human readable description of the node (e. g. folder)
15    * <li>value (Object): represent the content of a node (e. g. file)
16    * <li>parent (String): reference of the UUID to the parent node
17    *
18    * @param <T> define the TreeType
19    *
20    * @author elmar.dott@gmail.com
21    * @version 1.2
22    * @since 1.0
23    */
24    @API(status = STABLE, since = "1.0", consumers = "ListTree")
25    @Component
 
26    public interface TreeWalker<T> {
27   
28    /**
29    * Identifier for the given feature.
30    */
31    @API(status = STABLE, since = "1.2")
32    String FEATURE_ID = "CM-09";
33   
34    /**
35    * Add the root node to the tree.
36    *
37    * @param root as TreeNode
38    * @return true on success
39    */
40    @API(status = STABLE, since = "1.0")
41    boolean addRoot(TreeNode<T> root);
42   
43    /**
44    * Test if a node is a element of the tree. <b>This function do not validate
45    * if all tree elements are well connected.</b> This tests returns true if
46    * the element is added to the tree list.
47    *
48    * @param node as TreeNode
49    * @return true on success
50    */
51    @API(status = STABLE, since = "1.0")
52    boolean isElementOfTree(TreeNode<T> node);
53   
54    /**
55    * Check if the representing tree is empty.
56    *
57    * @return true n success
58    */
59    @API(status = STABLE, since = "1.0")
60    boolean isEmpty();
61   
62    /**
63    * Check if a given node is a leaf in the tree. Leafs don't have child
64    * nodes. => node.uuid != otherNode.getParent
65    *
66    * @param node as TreeNode
67    * @return true on success
68    */
69    @API(status = STABLE, since = "1.0")
70    boolean isLeaf(TreeNode<T> node);
71   
72    /**
73    * Removes a Node (leaf) from the tree. This method allows just to cut
74    * elements from the tree which has no children. In the case it is necessary
75    * to cut a subtree use the prune() method.
76    *
77    * @param node as TreeNode
78    * @return true on success
79    */
80    @API(status = STABLE, since = "1.0")
81    boolean removeNode(TreeNode<T> node);
82   
83    /**
84    * Count the nodes of the tree.
85    *
86    * @return count as int
87    */
88    @API(status = STABLE, since = "1.0")
89    int countNodes();
90   
91    /**
92    * Test if a element name exist more than one time. Useful to get to know
93    * how often a name is used. Return the count how often the name for this
94    * element already appear in the data structure.
95    *
96    * @param nodeName as String
97    * @return count as int
98    */
99    @API(status = STABLE, since = "1.0")
100    int isNameUnique(String nodeName);
101   
102    /**
103    * Get all nodes of the tree with the same NodeName.
104    *
105    * @param nodeName as String
106    * @return nodes as List
107    */
108    @API(status = STABLE, since = "1.0")
109    List<TreeNode<T>> getElementByName(String nodeName);
110   
111    /**
112    * Get all leaf nodes of the tree.
113    *
114    * @return leafs as List
115    */
116    @API(status = STABLE, since = "1.0")
117    List<TreeNode<T>> getLeafs();
118   
119    /**
120    * Get the full tree.
121    *
122    * @return tree as List
123    */
124    @API(status = STABLE, since = "1.0")
125    List<TreeNode<T>> getTree();
126   
127    /**
128    * Get a TreeNode by his UUID.
129    *
130    * @param uuid as String
131    * @return node as TreeNode
132    */
133    @API(status = STABLE, since = "1.0")
134    TreeNode<T> getNodeByUuid(String uuid);
135   
136    /**
137    * Get the root TreeNode. If no root is set the return will be NULL.
138    *
139    * @return root as TreeNode
140    */
141    @API(status = STABLE, since = "3.0")
142    TreeNode<T> getRoot();
143   
144    /**
145    * Add the node to the tree. Check if the node is already exist in the tree
146    * by comparing the UUID. In the case there exist a node already with the
147    * UUID then the new one will not added. Another check is that not exist two
148    * nodes with the same name and the same parent. Also for this case the node
149    * will not be added to the tree.
150    *
151    * @param node as TreeNode
152    * @return true on success
153    */
154    @API(status = STABLE, since = "1.0")
155    boolean addNode(TreeNode<T> node);
156   
157    /**
158    * Reset all internal data of the TreeWalker.
159    */
160    @API(status = STABLE, since = "1.0")
161    void clear();
162   
163    /**
164    * Remove an element and all his child nodes from the tree.
165    *
166    * @param cutNode as TreeNode
167    * @throws org.europa.together.exceptions.MisconfigurationException
168    */
169    @API(status = STABLE, since = "1.0")
170    void prune(TreeNode<T> cutNode) throws MisconfigurationException;
171   
172    /**
173    * Merge another Tree (TreeWalker) into the present tree. After choosing a
174    * node from the present tree the whole new three (including) the ROOT
175    * element will apped on the chosen merge node.
176    *
177    * @param parentUuid as String
178    * @param appendingTree as TreeWalker
179    */
180    @API(status = STABLE, since = "1.0")
181    void merge(String parentUuid, TreeWalker<T> appendingTree);
182   
183    /**
184    * Check if the tree is valid. A valid tree has no "unconnected" elements
185    * (treeNodes). There are three failure types:<br>
186    * <li>1: Single TreeNode elements without a parent</li>
187    * <li>2: Connected TreeNode fragments without a root</li>
188    * <li>3: Multiple Trees with root element</li>
189    * Those three types can occur in various combinations.
190    *
191    * @param tree as List
192    * @return true on success
193    * @throws org.europa.together.exceptions.MisconfigurationException
194    */
195    @API(status = STABLE, since = "2.1")
196    boolean validateTree(List<TreeNode<T>> tree) throws MisconfigurationException;
197    }