summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/data/Tree.java
diff options
context:
space:
mode:
authorbjculkin <bjculkin@mix.wvu.edu>2017-03-17 19:28:59 -0400
committerbjculkin <bjculkin@mix.wvu.edu>2017-03-17 19:28:59 -0400
commit5832ef0286430d04484b70d49c73e081a80ec9c7 (patch)
tree04ab56561978c14415f71b934f7d8a3aaa1a037e /BJC-Utils2/src/main/java/bjc/utils/data/Tree.java
parentc8593896ba0d93c9512a71c2e70d1d503627b1b0 (diff)
Add more toString/hashCode/equals
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/data/Tree.java')
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/Tree.java36
1 files changed, 21 insertions, 15 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/Tree.java b/BJC-Utils2/src/main/java/bjc/utils/data/Tree.java
index 52414d2..68da7ac 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/Tree.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/Tree.java
@@ -301,28 +301,34 @@ public class Tree<ContainedType> implements ITree<ContainedType> {
}
@Override
- public boolean equals(Object other) {
- if(!(other instanceof Tree<?>)) return false;
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
- @SuppressWarnings("unchecked")
- Tree<ContainedType> otr = (Tree<ContainedType>) other;
+ result = prime * result + childCount;
+ result = prime * result + ((children == null) ? 0 : children.hashCode());
+ result = prime * result + ((data == null) ? 0 : data.hashCode());
- if(!otr.data.equals(data)) return false;
-
- if(children == null && otr.children == null) return true;
+ return result;
+ }
- if(children == null && otr.children != null) return false;
- if(children != null && otr.children == null) return false;
+ @Override
+ public boolean equals(Object obj) {
+ if(this == obj) return true;
+ if(obj == null) return false;
+ if(getClass() != obj.getClass()) return false;
- if(children.getSize() != otr.children.getSize()) return false;
+ Tree<?> other = (Tree<?>) obj;
- int childNo = 0;
+ if(data == null) {
+ if(other.data != null) return false;
+ } else if(!data.equals(other.data)) return false;
- for(ITree<ContainedType> child : children) {
- if(!otr.children.getByIndex(childNo).equals(child)) return false;
+ if(childCount != other.childCount) return false;
- childNo += 1;
- }
+ if(children == null) {
+ if(other.children != null) return false;
+ } else if(!children.equals(other.children)) return false;
return true;
}