-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathFpNode.java
108 lines (95 loc) · 1.7 KB
/
FpNode.java
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import java.util.ArrayList;
import java.util.List;
public class FpNode {
String idName;// id号
List<FpNode> children;// 孩子结点
FpNode parent;// 父结点
FpNode next;// 下一个id号相同的结点
long count;// 出现次数
public FpNode() {// 用于构造根结点
this.idName = null;
this.count = -1;
children = new ArrayList<FpNode>();
next = null;
parent = null;
}
/**
* 用于构造非跟结点
*
* @param idName
* @param count
*/
public FpNode(String idName) {
this.idName = idName;
this.count = 1;
children = new ArrayList<FpNode>();
next = null;
parent = null;
}
/**
* 用于生成非跟结点
*
* @param idName
* @param count
*/
public FpNode(String idName, long count) {
this.idName = idName;
this.count = count;
children = new ArrayList<FpNode>();
next = null;
parent = null;
}
/**
* 添加一个孩子
*
* @param child
*/
public void addChild(FpNode child) {
children.add(child);
}
public void addCount(int count) {
this.count += count;
}
/**
* 计算器加1
*/
public void addCount() {
this.count += 1;
}
/**
* 设置下一个结点
*
* @param next
*/
public void setNextNode(FpNode next) {
this.next = next;
}
public void setParent(FpNode parent) {
this.parent = parent;
}
/**
* 指定取孩子
*
* @param index
* @return
*/
public FpNode getChilde(int index) {
return children.get(index);
}
/**
* 查找是否包含id号为idName的孩子
*
* @param idName
* @return
*/
public int hasChild(String idName) {
for (int i = 0; i < children.size(); i++)
if (children.get(i).idName.equals(idName))
return i;
return -1;
}
public String toString() {
return "id: " + idName + " count: " + count + " 孩子个数 "
+ children.size();
}
}