diff --git a/src/main/java/net/vivin/GenericTreeNode.java b/src/main/java/net/vivin/GenericTreeNode.java index b973355..a063436 100755 --- a/src/main/java/net/vivin/GenericTreeNode.java +++ b/src/main/java/net/vivin/GenericTreeNode.java @@ -71,6 +71,18 @@ public void removeChildAt(int index) throws IndexOutOfBoundsException { public GenericTreeNode getChildAt(int index) throws IndexOutOfBoundsException { return children.get(index); } + + public Set> getAllLeafNodes() { + Set> leafNodes = new HashSet>(); + if (this.children.isEmpty()) { + leafNodes.add(this); + } else { + for (GenericTreeNode child : this.children) { + leafNodes.addAll(child.getAllLeafNodes()); + } + } + return leafNodes; + } public T getData() { return this.data;