150
|
1 package jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index;
|
|
2
|
151
|
3 import java.util.Iterator;
|
|
4
|
150
|
5 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode;
|
151
|
6 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNodeChildren;
|
150
|
7 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.TreeMapOrd;
|
166
|
8 import fj.Ord;
|
150
|
9 import fj.data.Option;
|
|
10 import fj.data.TreeMap;
|
|
11
|
|
12 public class ParentIndex {
|
153
|
13
|
158
|
14 private TreeMap<TreeNode, TreeNode> parentIndex;
|
150
|
15
|
|
16 public ParentIndex() {
|
172
|
17 System.out.println(System.getProperty("java.version"));
|
|
18 parentIndex = TreeMap.empty(TreeMapOrd.treeNodeOrd);
|
150
|
19 }
|
|
20
|
|
21 public ParentIndex(TreeMap<TreeNode, TreeNode> parentIndex) {
|
|
22 this.parentIndex = parentIndex;
|
|
23 }
|
153
|
24
|
|
25 public boolean isEmpty(){
|
|
26 return parentIndex.isEmpty();
|
|
27 }
|
158
|
28
|
150
|
29 public ParentIndex(ParentIndex parentIndex) {
|
|
30 this.parentIndex = parentIndex.getParentIndex();
|
|
31 }
|
|
32
|
153
|
33 public TreeMap<TreeNode, TreeNode> getParentIndex() {
|
150
|
34 return parentIndex;
|
|
35 }
|
|
36
|
153
|
37 public TreeNode get(TreeNode child) {
|
150
|
38 Option<TreeNode> parentOp = parentIndex.get(child);
|
153
|
39 if (parentOp.isSome())
|
|
40 return parentOp.some();
|
|
41 return null;
|
150
|
42 }
|
153
|
43
|
169
|
44 public ParentIndex set(TreeNode parent ,TreeNode child) {
|
|
45 parentIndex = parentIndex.set(child, parent);
|
158
|
46 return this;
|
150
|
47 }
|
153
|
48
|
150
|
49 public ParentIndex delete(TreeNode child) {
|
158
|
50 parentIndex = parentIndex.delete(child);
|
|
51 return this;
|
150
|
52 }
|
|
53
|
151
|
54 public ParentIndex deleteAllChildren(TreeNode parentNode) {
|
|
55 TreeNodeChildren children = parentNode.getChildren();
|
|
56 Iterator<TreeNode> childrenIterator = children.iterator();
|
|
57 for (; childrenIterator.hasNext();) {
|
|
58 TreeNode child = childrenIterator.next();
|
158
|
59 parentIndex = parentIndex.delete(child);
|
151
|
60 }
|
158
|
61 return this;
|
151
|
62 }
|
|
63
|
|
64 public ParentIndex addAllChildren(TreeNode parentNode) {
|
|
65 TreeNodeChildren children = parentNode.getChildren();
|
|
66 Iterator<TreeNode> childrenIterator = children.iterator();
|
|
67 for (; childrenIterator.hasNext();) {
|
|
68 TreeNode child = childrenIterator.next();
|
158
|
69 parentIndex = parentIndex.set(child, parentNode);
|
151
|
70 }
|
158
|
71 return this;
|
151
|
72 }
|
|
73
|
150
|
74 }
|