Mercurial > hg > Members > tatsuki > bench > jungle-core
annotate src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/PutIndexEditor.java @ 143:afbe19c98f53
change Index form TreeMap<String,TreeMap<String<List<Pair<TreeNode,NodePath>>>> → TreeMap<String,TreeMap<String<List<NodePath>>>
bag
author | one |
---|---|
date | Sat, 15 Nov 2014 17:48:07 +0900 |
parents | 99bda30ea72c |
children |
rev | line source |
---|---|
118 | 1 package jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index; |
2 | |
3 | |
128 | 4 |
5 import fj.Ord; | |
6 import fj.data.List; | |
7 import fj.data.Option; | |
8 import fj.data.TreeMap; | |
9 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; | |
10 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.TreeEditor; | |
11 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; | |
12 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.TreeOperationLog; | |
118 | 13 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.IndexJungleTreeEditor; |
128 | 14 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.TransactionManager; |
15 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither; | |
118 | 16 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; |
17 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; | |
128 | 18 |
19 import java.nio.ByteBuffer; | |
118 | 20 |
21 public class PutIndexEditor implements IndexEditor { | |
22 | |
128 | 23 String key; |
24 String attribute; | |
25 NodePath path; | |
26 TransactionManager txManager; | |
27 TreeNode root; | |
28 TreeEditor editor; | |
29 TreeOperationLog log; | |
30 | |
31 public PutIndexEditor(String key, ByteBuffer attribute,NodePath path) { | |
137 | 32 this.key = key; |
33 this.attribute = new String(attribute.array()); | |
34 this.path = path; | |
128 | 35 } |
36 | |
118 | 37 @Override |
143
afbe19c98f53
change Index form TreeMap<String,TreeMap<String<List<Pair<TreeNode,NodePath>>>> → TreeMap<String,TreeMap<String<List<NodePath>>>
one
parents:
140
diff
changeset
|
38 public Either<Error, IndexJungleTreeEditor> edit(TreeNode root,TransactionManager txManager,TreeEditor editor,TreeOperationLog log,TreeMap<String, TreeMap<String, List<NodePath>>> index) { |
afbe19c98f53
change Index form TreeMap<String,TreeMap<String<List<Pair<TreeNode,NodePath>>>> → TreeMap<String,TreeMap<String<List<NodePath>>>
one
parents:
140
diff
changeset
|
39 TreeMap<String, TreeMap<String, List<NodePath>>> newIndex = editIndex(path, key, attribute,index); |
128 | 40 IndexJungleTreeEditor newEditor = new IndexJungleTreeEditor(root,txManager,editor,log, newIndex); |
130 | 41 Either<Error, IndexJungleTreeEditor> either = DefaultEither.newB(newEditor); |
128 | 42 return either; |
118 | 43 } |
128 | 44 |
143
afbe19c98f53
change Index form TreeMap<String,TreeMap<String<List<Pair<TreeNode,NodePath>>>> → TreeMap<String,TreeMap<String<List<NodePath>>>
one
parents:
140
diff
changeset
|
45 public TreeMap<String, TreeMap<String, List<NodePath>>> editIndex(NodePath path, String key, String attribute,TreeMap<String, TreeMap<String, List<NodePath>>> index){ |
128 | 46 |
143
afbe19c98f53
change Index form TreeMap<String,TreeMap<String<List<Pair<TreeNode,NodePath>>>> → TreeMap<String,TreeMap<String<List<NodePath>>>
one
parents:
140
diff
changeset
|
47 Option<TreeMap<String, List<NodePath>>> innerIndexOp = index.get(key); |
128 | 48 |
49 if (attribute != null) { | |
50 if (innerIndexOp.isNone()) { | |
51 | |
143
afbe19c98f53
change Index form TreeMap<String,TreeMap<String<List<Pair<TreeNode,NodePath>>>> → TreeMap<String,TreeMap<String<List<NodePath>>>
one
parents:
140
diff
changeset
|
52 TreeMap<String, List<NodePath>> innerIndex = TreeMap.empty(Ord.stringOrd); |
afbe19c98f53
change Index form TreeMap<String,TreeMap<String<List<Pair<TreeNode,NodePath>>>> → TreeMap<String,TreeMap<String<List<NodePath>>>
one
parents:
140
diff
changeset
|
53 List<NodePath> list = List.nil(); |
afbe19c98f53
change Index form TreeMap<String,TreeMap<String<List<Pair<TreeNode,NodePath>>>> → TreeMap<String,TreeMap<String<List<NodePath>>>
one
parents:
140
diff
changeset
|
54 list = list.cons(path); |
137 | 55 innerIndex = innerIndex.set(attribute, list); |
143
afbe19c98f53
change Index form TreeMap<String,TreeMap<String<List<Pair<TreeNode,NodePath>>>> → TreeMap<String,TreeMap<String<List<NodePath>>>
one
parents:
140
diff
changeset
|
56 TreeMap<String, TreeMap<String, List<NodePath>>> newIndex = index.set(key, innerIndex); |
139 | 57 return newIndex; |
128 | 58 } else { |
59 | |
143
afbe19c98f53
change Index form TreeMap<String,TreeMap<String<List<Pair<TreeNode,NodePath>>>> → TreeMap<String,TreeMap<String<List<NodePath>>>
one
parents:
140
diff
changeset
|
60 TreeMap<String, List<NodePath>> innerIndex = innerIndexOp.some(); |
140 | 61 |
143
afbe19c98f53
change Index form TreeMap<String,TreeMap<String<List<Pair<TreeNode,NodePath>>>> → TreeMap<String,TreeMap<String<List<NodePath>>>
one
parents:
140
diff
changeset
|
62 Option<List<NodePath>> opList = innerIndex.get(attribute); |
128 | 63 |
64 if (opList.isNone()) { | |
65 | |
143
afbe19c98f53
change Index form TreeMap<String,TreeMap<String<List<Pair<TreeNode,NodePath>>>> → TreeMap<String,TreeMap<String<List<NodePath>>>
one
parents:
140
diff
changeset
|
66 List<NodePath> list = List.nil(); |
afbe19c98f53
change Index form TreeMap<String,TreeMap<String<List<Pair<TreeNode,NodePath>>>> → TreeMap<String,TreeMap<String<List<NodePath>>>
one
parents:
140
diff
changeset
|
67 list = list.cons(path); |
128 | 68 innerIndex = innerIndex.set(attribute, list); |
69 | |
70 } else { | |
71 | |
143
afbe19c98f53
change Index form TreeMap<String,TreeMap<String<List<Pair<TreeNode,NodePath>>>> → TreeMap<String,TreeMap<String<List<NodePath>>>
one
parents:
140
diff
changeset
|
72 List<NodePath> list = opList.some(); |
afbe19c98f53
change Index form TreeMap<String,TreeMap<String<List<Pair<TreeNode,NodePath>>>> → TreeMap<String,TreeMap<String<List<NodePath>>>
one
parents:
140
diff
changeset
|
73 list = list.cons(path); |
128 | 74 innerIndex = innerIndex.set(attribute, list); |
75 | |
76 } | |
143
afbe19c98f53
change Index form TreeMap<String,TreeMap<String<List<Pair<TreeNode,NodePath>>>> → TreeMap<String,TreeMap<String<List<NodePath>>>
one
parents:
140
diff
changeset
|
77 TreeMap<String, TreeMap<String, List<NodePath>>> newIndex = index.set(key, innerIndex); |
128 | 78 return newIndex; |
79 } | |
80 } | |
81 return index; | |
82 } | |
83 | |
143
afbe19c98f53
change Index form TreeMap<String,TreeMap<String<List<Pair<TreeNode,NodePath>>>> → TreeMap<String,TreeMap<String<List<NodePath>>>
one
parents:
140
diff
changeset
|
84 // public TreeNode getTarget(TreeNode node , NodePath path){ |
afbe19c98f53
change Index form TreeMap<String,TreeMap<String<List<Pair<TreeNode,NodePath>>>> → TreeMap<String,TreeMap<String<List<NodePath>>>
one
parents:
140
diff
changeset
|
85 // Pair<Integer, NodePath> path = path.pop(); |
afbe19c98f53
change Index form TreeMap<String,TreeMap<String<List<Pair<TreeNode,NodePath>>>> → TreeMap<String,TreeMap<String<List<NodePath>>>
one
parents:
140
diff
changeset
|
86 // Either<Error, TreeNode> either = node.getChildren().at(path.left()); |
afbe19c98f53
change Index form TreeMap<String,TreeMap<String<List<Pair<TreeNode,NodePath>>>> → TreeMap<String,TreeMap<String<List<NodePath>>>
one
parents:
140
diff
changeset
|
87 // if (either.isA()) |
afbe19c98f53
change Index form TreeMap<String,TreeMap<String<List<Pair<TreeNode,NodePath>>>> → TreeMap<String,TreeMap<String<List<NodePath>>>
one
parents:
140
diff
changeset
|
88 // return node; |
afbe19c98f53
change Index form TreeMap<String,TreeMap<String<List<Pair<TreeNode,NodePath>>>> → TreeMap<String,TreeMap<String<List<NodePath>>>
one
parents:
140
diff
changeset
|
89 // |
afbe19c98f53
change Index form TreeMap<String,TreeMap<String<List<Pair<TreeNode,NodePath>>>> → TreeMap<String,TreeMap<String<List<NodePath>>>
one
parents:
140
diff
changeset
|
90 // TreeNode child = either.b(); |
afbe19c98f53
change Index form TreeMap<String,TreeMap<String<List<Pair<TreeNode,NodePath>>>> → TreeMap<String,TreeMap<String<List<NodePath>>>
one
parents:
140
diff
changeset
|
91 // if (path.right().size() == 0) |
afbe19c98f53
change Index form TreeMap<String,TreeMap<String<List<Pair<TreeNode,NodePath>>>> → TreeMap<String,TreeMap<String<List<NodePath>>>
one
parents:
140
diff
changeset
|
92 // return child; |
afbe19c98f53
change Index form TreeMap<String,TreeMap<String<List<Pair<TreeNode,NodePath>>>> → TreeMap<String,TreeMap<String<List<NodePath>>>
one
parents:
140
diff
changeset
|
93 // |
afbe19c98f53
change Index form TreeMap<String,TreeMap<String<List<Pair<TreeNode,NodePath>>>> → TreeMap<String,TreeMap<String<List<NodePath>>>
one
parents:
140
diff
changeset
|
94 // TreeNode target = getTarget(child,path.right()); |
afbe19c98f53
change Index form TreeMap<String,TreeMap<String<List<Pair<TreeNode,NodePath>>>> → TreeMap<String,TreeMap<String<List<NodePath>>>
one
parents:
140
diff
changeset
|
95 // return target; |
afbe19c98f53
change Index form TreeMap<String,TreeMap<String<List<Pair<TreeNode,NodePath>>>> → TreeMap<String,TreeMap<String<List<NodePath>>>
one
parents:
140
diff
changeset
|
96 // } |
128 | 97 |
118 | 98 } |