-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTreeNode.java
58 lines (46 loc) · 1.29 KB
/
TreeNode.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
import java.util.HashMap;
import java.util.Collection;
// The node class of which the FP Tree is composed.
// All functions were are self-documenting.
public class TreeNode {
private TreeNode parent;
private HashMap<Integer, TreeNode> children;
private int item;
private int support;
public TreeNode(int item, TreeNode parent) {
this.parent = parent;
children = new HashMap<>();
this.item = item;
support = 1;
}
public TreeNode(int item, TreeNode parent, int support) {
this(item, parent);
this.support = support;
}
public int item() {
return item;
}
public void incrementSupport(int amount) {
support += amount;
}
public int getSupport() {
return support;
}
// Adds a (deep copy) of a node as a child to this node
public void addChild(int item, int support) {
TreeNode childNode = new TreeNode(item, this, support);
children.put(item, childNode);
}
public TreeNode getChild(int item) {
return children.get(item);
}
public boolean hasChild(int item) {
return children.get(item) != null;
}
public TreeNode getParent() {
return parent;
}
public boolean hasParent() {
return parent != null;
}
}