APL/DEV 3.2/TP07/Repertoires/Node.java
2022-11-24 15:17:33 +01:00

42 lines
886 B
Java

import java.util.Collection;
import java.util.HashSet;
public class Node<T> {
private T value;
private Collection<Node<T>> 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<Node<T>> getSubNodes() {
return this.subNodes;
}
public boolean addSubNode(Node<T> node) {
return subNodes.add(node);
}
public boolean remSubNode(Node<T> 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<T> subNode : subNodes) {
subNode.showNode(level + 1);
}
}
}