150
|
1 package jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index;
|
|
2
|
|
3 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode;
|
|
4 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.TreeMapOrd;
|
|
5 import fj.data.Option;
|
|
6 import fj.data.TreeMap;
|
|
7
|
|
8 public class ParentIndex {
|
|
9
|
|
10 private final TreeMap<TreeNode, TreeNode> parentIndex;
|
|
11
|
|
12 public ParentIndex() {
|
|
13 parentIndex = TreeMap.empty(TreeMapOrd.treeNodeOrd);
|
|
14 }
|
|
15
|
|
16 public ParentIndex(TreeMap<TreeNode, TreeNode> parentIndex) {
|
|
17 this.parentIndex = parentIndex;
|
|
18 }
|
|
19
|
|
20 public ParentIndex(ParentIndex parentIndex) {
|
|
21 this.parentIndex = parentIndex.getParentIndex();
|
|
22 }
|
|
23
|
|
24 private TreeMap<TreeNode, TreeNode> getParentIndex() {
|
|
25 return parentIndex;
|
|
26 }
|
|
27
|
|
28 public Option<TreeNode> get(TreeNode child) {
|
|
29 Option<TreeNode> parentOp = parentIndex.get(child);
|
|
30 return parentOp;
|
|
31 }
|
|
32
|
|
33 public ParentIndex set(TreeNode child, TreeNode parent){
|
|
34 TreeMap<TreeNode, TreeNode> newParentIndex = parentIndex.set(child,parent);
|
|
35 return new ParentIndex(newParentIndex);
|
|
36 }
|
|
37
|
|
38 public ParentIndex delete(TreeNode child) {
|
|
39 TreeMap<TreeNode, TreeNode> newParentIndex = parentIndex.delete(child);
|
|
40 return new ParentIndex(newParentIndex);
|
|
41 }
|
|
42
|
|
43 }
|