97
|
1 package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser;
|
|
2
|
98
|
3 import java.util.Iterator;
|
132
|
4 import java.util.concurrent.atomic.AtomicReference;
|
98
|
5
|
112
|
6 import fj.Ord;
|
104
|
7 import fj.data.List;
|
124
|
8 import fj.data.Option;
|
97
|
9 import fj.data.TreeMap;
|
98
|
10 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree;
|
101
|
11 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor;
|
132
|
12 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeList;
|
|
13 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.ChangeSet;
|
97
|
14 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath;
|
|
15 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode;
|
132
|
16 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.AtomicReservableReference;
|
|
17 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.DefaultChangeSet;
|
|
18 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.DefaultTreeContext;
|
127
|
19 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.IndexJungleTreeEditor;
|
132
|
20 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.TreeContext;
|
97
|
21 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair;
|
99
|
22 import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.query.PathNodeIterator;
|
110
|
23 import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.query.Query;
|
134
|
24 import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.IndexManager;
|
97
|
25
|
100
|
26 public class InterfaceTraverser {
|
124
|
27
|
127
|
28 //InterfaceTraverser traverser;
|
98
|
29 TreeNode node;
|
111
|
30 TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index;
|
134
|
31 IndexManager indexManager;
|
127
|
32
|
134
|
33 public InterfaceTraverser(TreeNode _root, IndexManager indexManager) {
|
127
|
34 this.node = _root;
|
|
35 this.index = TreeMap.empty(Ord.stringOrd);
|
134
|
36 this.indexManager = indexManager;
|
127
|
37 }
|
|
38
|
|
39 public InterfaceTraverser(
|
|
40 TreeNode _root,
|
|
41 TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index,
|
134
|
42 IndexManager indexManager) {
|
127
|
43 this.node = _root;
|
|
44 this.index = index;
|
134
|
45 this.indexManager = indexManager;
|
127
|
46 }
|
|
47
|
132
|
48 public void commitIndex(){
|
134
|
49 indexManager.commit(index);
|
127
|
50 }
|
126
|
51
|
125
|
52 public TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> getIndex() {
|
|
53 return index;
|
|
54 }
|
|
55
|
|
56 public void setIndex(
|
|
57 TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index) {
|
|
58 this.index = index;
|
|
59 }
|
|
60
|
127
|
61
|
|
62
|
132
|
63 /* public InterfaceTraverser getTraverser(JungleTree tree) {
|
124
|
64 return new InterfaceTraverser(tree.getRootNode(), tree.getIndex(),
|
127
|
65 tree.getIndexTreeEditor());
|
132
|
66 }*/
|
98
|
67
|
124
|
68 public void set(TreeNode root) {
|
101
|
69 this.node = root;
|
|
70 }
|
124
|
71
|
|
72
|
101
|
73
|
134
|
74 public Iterator<Pair<TreeNode, NodePath>> find(Query query, String key, String searchValue) {
|
105
|
75
|
131
|
76 if (index.get(key).isSome()) {
|
124
|
77
|
|
78 TreeMap<String, List<Pair<TreeNode, NodePath>>> innerIndex = this.index.get(key).some();
|
|
79 Option<List<Pair<TreeNode, NodePath>>> opList = innerIndex.get(searchValue);
|
|
80
|
|
81 if (opList.isNone())
|
126
|
82 return null;//空のIteratorを返す
|
99
|
83
|
124
|
84 final List<Pair<TreeNode, NodePath>> list = opList.some();
|
|
85 return list.iterator();
|
|
86
|
|
87 } else {
|
|
88
|
|
89 final PathNodeIterator itNode = new PathNodeIterator(node);
|
|
90 return new Iterator<Pair<TreeNode, NodePath>>() {
|
|
91
|
|
92 private Pair<TreeNode, NodePath> matchPair = nextmatch(itNode);
|
|
93
|
|
94 private Pair<TreeNode, NodePath> nextmatch(
|
|
95 PathNodeIterator itNode) {
|
101
|
96
|
124
|
97 for (; itNode.hasNext();) {
|
|
98 Pair<TreeNode, NodePath> pathNode = itNode.next();
|
|
99 String value = pathNode.left().getAttributes().getString(key);
|
|
100 Option<TreeMap<String, List<Pair<TreeNode, NodePath>>>> innerIndexOp = index.get(key);
|
|
101
|
|
102 if (value != null) {
|
|
103 if (innerIndexOp.isNone()) {
|
|
104
|
|
105 TreeMap<String, List<Pair<TreeNode, NodePath>>> innerIndex = TreeMap.empty(Ord.stringOrd);
|
|
106 List<Pair<TreeNode, NodePath>> list = List.nil();
|
|
107 list = list.cons(pathNode);
|
|
108 innerIndex = innerIndex.set(value, list);
|
|
109 index = index.set(key, innerIndex);
|
|
110
|
|
111 } else {
|
|
112
|
|
113 TreeMap<String, List<Pair<TreeNode, NodePath>>> innerIndex = innerIndexOp.some();
|
|
114 Option<List<Pair<TreeNode, NodePath>>> opList = innerIndex.get(value);
|
|
115
|
|
116 if (opList.isNone()) {
|
99
|
117
|
124
|
118 List<Pair<TreeNode, NodePath>> list = List.nil();
|
|
119 list = list.cons(pathNode);
|
|
120 innerIndex = innerIndex.set(value, list);
|
|
121
|
|
122 } else {
|
|
123
|
|
124 List<Pair<TreeNode, NodePath>> list = opList.some();
|
|
125 list = list.cons(pathNode);
|
|
126 innerIndex = innerIndex.set(value, list);
|
|
127
|
|
128 }
|
|
129 index = index.set(key, innerIndex);
|
|
130
|
|
131 }
|
|
132 }
|
|
133
|
|
134 if (query.condition(pathNode.left()))
|
|
135 return pathNode;
|
|
136 }
|
|
137 return null;
|
|
138 }
|
99
|
139
|
124
|
140 @Override
|
|
141 public boolean hasNext() {
|
|
142 if (matchPair == null) {
|
|
143 // index = itNode.getIndex();
|
|
144 return false;
|
|
145 }
|
|
146 return true;
|
|
147 }
|
99
|
148
|
124
|
149 @Override
|
|
150 public Pair<TreeNode, NodePath> next() {
|
|
151 Pair<TreeNode, NodePath> currentPair = matchPair;
|
|
152 matchPair = nextmatch(itNode);
|
|
153 return currentPair;
|
|
154 }
|
101
|
155
|
124
|
156 @Override
|
|
157 public void remove() {
|
|
158 // TODO Auto-generated method stub
|
99
|
159
|
124
|
160 }
|
99
|
161
|
124
|
162 };
|
|
163 }
|
98
|
164 }
|
97
|
165 }
|