| 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 | public TreeNode() { | |
| 30 | this.uuid = StringUtils.generateUUID(); | |
| 31 | } | |
| 32 | ||
| 33 | /** | |
| 34 | * Constructor. | |
| 35 | * | |
| 36 | * @param name as String | |
| 37 | */ | |
| 38 | public TreeNode(final String name) { | |
| 39 | this.uuid = StringUtils.generateUUID(); | |
| 40 | 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 | public String getNodeName() { | |
| 50 |
1
1. getNodeName : replaced return value with "" for org/europa/together/domain/TreeNode::getNodeName → KILLED |
return nodeName; |
| 51 | } | |
| 52 | ||
| 53 | /** | |
| 54 | * Set the name of the node. | |
| 55 | * | |
| 56 | * @param nodeName as String | |
| 57 | */ | |
| 58 | public void setNodeName(final String nodeName) { | |
| 59 | this.nodeName = nodeName; | |
| 60 | } | |
| 61 | ||
| 62 | /** | |
| 63 | * Get the UUID of the parent node. | |
| 64 | * | |
| 65 | * @return UUID as String | |
| 66 | */ | |
| 67 | public String getParent() { | |
| 68 |
1
1. getParent : replaced return value with "" for org/europa/together/domain/TreeNode::getParent → KILLED |
return parent; |
| 69 | } | |
| 70 | ||
| 71 | /** | |
| 72 | * Set the UUID of the parent node. | |
| 73 | * | |
| 74 | * @param parent as String | |
| 75 | */ | |
| 76 | public void setParent(final String parent) { | |
| 77 | this.parent = parent; | |
| 78 | } | |
| 79 | ||
| 80 | /** | |
| 81 | * Get the value of a node. | |
| 82 | * | |
| 83 | * @return value as Object | |
| 84 | */ | |
| 85 | public T getValue() { | |
| 86 |
1
1. getValue : replaced return value with null for org/europa/together/domain/TreeNode::getValue → KILLED |
return value; |
| 87 | } | |
| 88 | ||
| 89 | /** | |
| 90 | * Set the value of a node. | |
| 91 | * | |
| 92 | * @param value as Object | |
| 93 | */ | |
| 94 | public void setValue(final T value) { | |
| 95 | this.value = value; | |
| 96 | } | |
| 97 | ||
| 98 | /** | |
| 99 | * Get the UUID of the node. | |
| 100 | * | |
| 101 | * @return uuid as String | |
| 102 | */ | |
| 103 | public String getUuid() { | |
| 104 |
1
1. getUuid : replaced return value with "" for org/europa/together/domain/TreeNode::getUuid → KILLED |
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 | public TreeNode<T> copy(final TreeNode<T> node) { | |
| 115 | TreeNode<T> copy = new TreeNode<>(); | |
| 116 | copy.uuid = node.uuid; | |
| 117 | copy.nodeName = node.nodeName; | |
| 118 | copy.parent = node.parent; | |
| 119 | copy.value = node.value; | |
| 120 |
1
1. copy : replaced return value with null for org/europa/together/domain/TreeNode::copy → KILLED |
return copy; |
| 121 | } | |
| 122 | ||
| 123 | @Override | |
| 124 | public String toString() { | |
| 125 |
1
1. toString : replaced return value with "" for org/europa/together/domain/TreeNode::toString → SURVIVED |
return "TreeNode{" + "uuid=" + uuid |
| 126 | + ", nodeName=" + nodeName | |
| 127 | + ", parent=" + parent | |
| 128 | + ", value=" + value + '}'; | |
| 129 | } | |
| 130 | ||
| 131 | @Override | |
| 132 | public int hashCode() { | |
| 133 |
2
1. hashCode : Replaced integer addition with subtraction → SURVIVED 2. hashCode : replaced int return with 0 for org/europa/together/domain/TreeNode::hashCode → KILLED |
return HASH + Objects.hashCode(this.nodeName); |
| 134 | } | |
| 135 | ||
| 136 | @Override | |
| 137 | public boolean equals(final Object obj) { | |
| 138 | boolean success = false; | |
| 139 |
2
1. equals : negated conditional → KILLED 2. equals : negated conditional → KILLED |
if (obj != null && obj instanceof TreeNode) { |
| 140 |
1
1. equals : negated conditional → KILLED |
if (this == obj) { |
| 141 | success = true; | |
| 142 | } else { | |
| 143 | final TreeNode<?> other = (TreeNode<?>) obj; | |
| 144 |
1
1. equals : negated conditional → KILLED |
if (Objects.equals(this.parent, other.parent) |
| 145 |
1
1. equals : negated conditional → KILLED |
&& Objects.equals(this.nodeName, other.nodeName)) { |
| 146 | success = true; | |
| 147 | } | |
| 148 | } | |
| 149 | } | |
| 150 |
1
1. equals : negated conditional → KILLED |
if (success) { |
| 151 | LOGGER.log(this.toString() + " == " + obj.toString(), LogLevel.DEBUG); | |
| 152 | } | |
| 153 |
2
1. equals : replaced boolean return with true for org/europa/together/domain/TreeNode::equals → KILLED 2. equals : replaced boolean return with false for org/europa/together/domain/TreeNode::equals → KILLED |
return success; |
| 154 | } | |
| 155 | } | |
Mutations | ||
| 50 |
1.1 |
|
| 68 |
1.1 |
|
| 86 |
1.1 |
|
| 104 |
1.1 |
|
| 120 |
1.1 |
|
| 125 |
1.1 |
|
| 133 |
1.1 2.2 |
|
| 139 |
1.1 2.2 |
|
| 140 |
1.1 |
|
| 144 |
1.1 |
|
| 145 |
1.1 |
|
| 150 |
1.1 |
|
| 153 |
1.1 2.2 |