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

File TreeNode.java

 

Coverage histogram

../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

8
28
13
1
155
79
19
0.68
2.15
13
1.46

Classes

Class Line # Actions
TreeNode 16 28 0% 19 0
1.0100%
 

Contributing tests

This file is covered by 44 tests. .

Source view

1    package org.europa.together.domain;
2   
3    import java.util.Objects;
4    import org.europa.together.application.LogbackLogger;
5    import org.europa.together.business.Logger;
6    import org.europa.together.utils.StringUtils;
7   
8    /**
9    * Data structure for a tree.A node is unique by is UUID, but in real
10    * environments is a more specified definition necessary. A parent node can not
11    * have two child nods with the same name. for a user is then hard to
12    * distinguish which child node is the right one. (e.g. Files and Folders)
13    *
14    * @param <T> as generic Class
15    */
 
16    public final class TreeNode<T> {
17   
18    private static final Logger LOGGER = new LogbackLogger(TreeNode.class);
19    private static final int HASH = 97;
20   
21    private String uuid;
22    private String nodeName;
23    private String parent;
24    private T value;
25   
26    /**
27    * Constructor.
28    */
 
29  18 toggle public TreeNode() {
30  18 this.uuid = StringUtils.generateUUID();
31    }
32   
33    /**
34    * Constructor.
35    *
36    * @param name as String
37    */
 
38  342 toggle public TreeNode(final String name) {
39  342 this.uuid = StringUtils.generateUUID();
40  342 this.nodeName = name;
41    }
42   
43    //<editor-fold defaultstate="collapsed" desc="Getter / Setter">
44    /**
45    * Get the name of the node.
46    *
47    * @return name as String
48    */
 
49  870 toggle public String getNodeName() {
50  870 return nodeName;
51    }
52   
53    /**
54    * Set the name of the node.
55    *
56    * @param nodeName as String
57    */
 
58  13 toggle public void setNodeName(final String nodeName) {
59  13 this.nodeName = nodeName;
60    }
61   
62    /**
63    * Get the UUID of the parent node.
64    *
65    * @return UUID as String
66    */
 
67  8064 toggle public String getParent() {
68  8064 return parent;
69    }
70   
71    /**
72    * Set the UUID of the parent node.
73    *
74    * @param parent as String
75    */
 
76  333 toggle public void setParent(final String parent) {
77  333 this.parent = parent;
78    }
79   
80    /**
81    * Get the value of a node.
82    *
83    * @return value as Object
84    */
 
85  5 toggle public T getValue() {
86  5 return value;
87    }
88   
89    /**
90    * Set the value of a node.
91    *
92    * @param value as Object
93    */
 
94  5 toggle public void setValue(final T value) {
95  5 this.value = value;
96    }
97   
98    /**
99    * Get the UUID of the node.
100    *
101    * @return uuid as String
102    */
 
103  5357 toggle public String getUuid() {
104  5357 return uuid;
105    }
106    //</editor-fold>
107   
108    /**
109    * Clone (copy) a TreeNode to a we instance.
110    *
111    * @param node as TreeNode
112    * @return a copy of the TreeNode
113    */
 
114  3 toggle public TreeNode<T> copy(final TreeNode<T> node) {
115  3 TreeNode<T> copy = new TreeNode<>();
116  3 copy.uuid = node.uuid;
117  3 copy.nodeName = node.nodeName;
118  3 copy.parent = node.parent;
119  3 copy.value = node.value;
120  3 return copy;
121    }
122   
 
123  174 toggle @Override
124    public String toString() {
125  174 return "TreeNode{" + "uuid=" + uuid
126    + ", nodeName=" + nodeName
127    + ", parent=" + parent
128    + ", value=" + value + '}';
129    }
130   
 
131  2 toggle @Override
132    public int hashCode() {
133  2 return HASH + Objects.hashCode(this.nodeName);
134    }
135   
 
136  874 toggle @Override
137    public boolean equals(final Object obj) {
138  874 boolean success = false;
139  874 if (obj != null && obj instanceof TreeNode) {
140  871 if (this == obj) {
141  69 success = true;
142    } else {
143  802 final TreeNode<?> other = (TreeNode<?>) obj;
144  802 if (Objects.equals(this.parent, other.parent)
145    && Objects.equals(this.nodeName, other.nodeName)) {
146  4 success = true;
147    }
148    }
149    }
150  874 if (success) {
151  73 LOGGER.log(this.toString() + " == " + obj.toString(), LogLevel.DEBUG);
152    }
153  874 return success;
154    }
155    }