128
|
1 package jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index;
|
|
2
|
134
|
3 import java.util.Iterator;
|
|
4
|
|
5 import fj.F;
|
|
6 import fj.Ord;
|
|
7 import fj.P2;
|
129
|
8 import fj.data.List;
|
134
|
9 import fj.data.Option;
|
129
|
10 import fj.data.TreeMap;
|
128
|
11 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor;
|
129
|
12 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath;
|
|
13 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.TreeEditor;
|
134
|
14 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath;
|
129
|
15 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode;
|
|
16 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.TreeOperationLog;
|
128
|
17 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.IndexJungleTreeEditor;
|
129
|
18 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.TransactionManager;
|
134
|
19 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither;
|
128
|
20 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either;
|
|
21 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error;
|
129
|
22 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair;
|
128
|
23
|
|
24 public class DeleteChildIndexEditor implements IndexEditor {
|
|
25
|
134
|
26 NodePath editNodePath;
|
|
27
|
|
28 public DeleteChildIndexEditor(int pos, NodePath path) {
|
|
29 this.editNodePath = path.add(pos);
|
|
30 }
|
|
31
|
128
|
32 @Override
|
130
|
33 public Either<Error, IndexJungleTreeEditor> edit(
|
129
|
34 TreeNode root,
|
|
35 TransactionManager txManager,
|
|
36 TreeEditor editor,
|
|
37 TreeOperationLog log,
|
|
38 TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index) {
|
134
|
39
|
|
40 TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> newIndex = editIndex(index);
|
|
41 IndexJungleTreeEditor newEditor = new IndexJungleTreeEditor(root, txManager, editor, newIndex);
|
|
42 return DefaultEither.newB(newEditor);
|
|
43 }
|
|
44
|
|
45 public TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> editIndex(
|
|
46 TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index) {
|
|
47
|
|
48 if (!index.isEmpty()) {
|
|
49 List<String> keyList = index.keys();
|
|
50 TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> newIndex = TreeMap.empty(Ord.stringOrd);
|
|
51 TreeMap<String, List<Pair<TreeNode, NodePath>>> newInnerIndex = TreeMap.empty(Ord.stringOrd);
|
|
52
|
|
53 for (String indexKey : keyList) {
|
|
54 TreeMap<String, List<Pair<TreeNode, NodePath>>> innerIndex = index.get(indexKey).some();
|
|
55 List<String> innerIndexKeyList = innerIndex.keys();
|
|
56
|
|
57 for (String innerIndexKey : innerIndexKeyList) {
|
|
58 List<Pair<TreeNode, NodePath>> pairList = innerIndex.get(innerIndexKey).some();
|
|
59 List<Pair<TreeNode, NodePath>> list = checkPath(pairList);
|
|
60 if (!list.isEmpty()){
|
|
61 System.out.println(new String(list.head().left().getAttributes().get("KEY").array()));
|
|
62 newInnerIndex = newInnerIndex.set(innerIndexKey, list);
|
|
63 }
|
|
64 }
|
|
65 newIndex = newIndex.set(indexKey, newInnerIndex);
|
|
66 }
|
|
67 return newIndex;
|
|
68 } else {
|
|
69 return index;
|
|
70 }
|
128
|
71 }
|
|
72
|
134
|
73 public List<Pair<TreeNode, NodePath>> checkPath(List<Pair<TreeNode, NodePath>> pairList){
|
129
|
74
|
134
|
75 List<Pair<TreeNode, NodePath>> list = List.nil();
|
|
76 for (Pair<TreeNode, NodePath> pair : pairList) {
|
|
77
|
|
78 NodePath path = pair.right();
|
|
79 System.out.println("oldPath = " + path.toString());
|
|
80 NodePath newPath = new DefaultNodePath();
|
|
81
|
|
82 if (path.toString().equals(editNodePath.toString())) {
|
|
83 continue;
|
|
84 }
|
|
85
|
|
86 if (editNodePath.size() > path.size()) {
|
|
87 list = list.cons(pair);
|
|
88 continue;
|
|
89 }
|
|
90
|
|
91 Pair<Integer, NodePath> editNodePathCopy = editNodePath.pop();
|
|
92 int loopCount = 0;
|
|
93
|
|
94 for (Integer pathInt : path) {
|
|
95 loopCount++;
|
|
96
|
|
97 if (pathInt == -1)
|
|
98 continue;
|
|
99 if (editNodePathCopy.right().size() > 0) {
|
135
|
100
|
134
|
101 editNodePathCopy = editNodePathCopy.right().pop();
|
135
|
102 if (loopCount == editNodePath.size() && editNodePathCopy.left() < pathInt) {
|
134
|
103 newPath = newPath.add(pathInt - 1);
|
|
104 continue;
|
|
105 }
|
|
106
|
|
107 if (!(editNodePathCopy.left() == pathInt)) {
|
|
108 newPath = path;
|
|
109 break;
|
|
110 }
|
|
111 }
|
|
112
|
|
113 newPath = newPath.add(pathInt);
|
|
114
|
|
115 }
|
|
116
|
|
117 System.out.println("newPath = " + newPath.toString());
|
|
118 Pair<TreeNode, NodePath> newPair = new Pair<TreeNode, NodePath>(
|
|
119 pair.left(), newPath);
|
|
120 list = list.cons(newPair);
|
|
121 }
|
|
122
|
|
123 return list;
|
|
124 }
|
129
|
125
|
128
|
126 }
|