From 3c7460950c060d93bffc395f074f09c18948d91c Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Mon, 20 Feb 2017 01:55:25 -0500 Subject: Minor updates --- BJC-Utils2/src/main/java/bjc/utils/data/Tree.java | 25 +++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'BJC-Utils2/src/main/java/bjc/utils/data/Tree.java') 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 implements ITree { action.accept(data); } } + + public boolean equals(Object other) { + if(!(other instanceof Tree)) return false; + + Tree otr = (Tree) 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 child : children) { + if(!otr.children.getByIndex(childNo).equals(child)) return false; + + childNo += 1; + } + + return true; + } } -- cgit v1.2.3