import java.util.Collection; import java.util.HashSet; public class Node { private T value; private Collection> subNodes; public Node(T value) { this.value = value; this.subNodes = new HashSet<>(); } public T getValue() { return value; } public void setValue(T value) { this.value = value; } public Collection> getSubNodes() { return this.subNodes; } public boolean addSubNode(Node node) { return subNodes.add(node); } public boolean remSubNode(Node node) { return subNodes.remove(node); } public void showNode(int level) { for (int i = 0; i < level; i++) System.out.print("\t"); System.out.println(value.toString()); for (Node subNode : subNodes) { subNode.showNode(level + 1); } } }