-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTreeNode.java
More file actions
47 lines (36 loc) · 833 Bytes
/
TreeNode.java
File metadata and controls
47 lines (36 loc) · 833 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package javaDesignpatterns.Compesite;
import java.util.Enumeration;
import java.util.Vector;
import javax.print.attribute.standard.RequestingUserName;
public class TreeNode {
private String name;
private TreeNode parent;
private Vector<TreeNode> children=new Vector<>();
public TreeNode(String name){
this.name=name;
}
public String getName() {
return name;
}
public TreeNode getParent() {
return parent;
}
public void setName(String name) {
this.name = name;
}
public void setParent(TreeNode parent) {
this.parent = parent;
}
//添加子节点
public void add(TreeNode node){
children.add(node);
}
//删除子节点
public void remove(TreeNode node){
children.remove(node);
}
//得到孩子节点
public Enumeration<TreeNode> getChildrens(){
return this.children.elements();
}
}