APL/DEV 3.2/TP07/Prefixe/Node.java

41 lines
802 B
Java
Raw Normal View History

2022-11-24 15:17:33 +01:00
import java.util.ArrayList;
import java.util.List;
public class Node<T> {
private T value;
private List<Node<T>> subNodes;
public Node(T value) {
this.value = value;
this.subNodes = new ArrayList<>();
}
public T getValue() {
return value;
}
public void setValue(T value) {
this.value = value;
}
public List<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() {
System.out.print(value.toString() + " ");
for (Node<T> subNode : subNodes) {
subNode.showNode();
}
}
}