diff options
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.java | 25 |
1 files changed, 25 insertions, 0 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 b812650..c44eece 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/Tree.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/Tree.java @@ -300,4 +300,29 @@ public class Tree<ContainedType> implements ITree<ContainedType> { action.accept(data); } } + + public boolean equals(Object other) { + if(!(other instanceof Tree)) return false; + + Tree<ContainedType> otr = (Tree<ContainedType>) other; + + if(!otr.data.equals(data)) return false; + + if(children == null && otr.children == null) return true; + + if(children == null && otr.children != null) return false; + if(children != null && otr.children == null) return false; + + if(children.getSize() != otr.children.getSize()) return false; + + int childNo = 0; + + for(ITree<ContainedType> child : children) { + if(!otr.children.getByIndex(childNo).equals(child)) return false; + + childNo += 1; + } + + return true; + } } |
