97
|
1 package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser;
|
|
2
|
98
|
3 import java.util.Iterator;
|
|
4
|
97
|
5 import fj.data.List;
|
|
6 import fj.data.TreeMap;
|
98
|
7 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree;
|
97
|
8 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath;
|
|
9 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode;
|
|
10 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair;
|
99
|
11 import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.query.PathNodeIterator;
|
98
|
12 import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.query.Query;
|
97
|
13
|
|
14 public class BruteForceTraverser {
|
98
|
15 BruteForceTraverser traverser;
|
|
16 TreeNode node;
|
97
|
17 TreeMap<String,TreeNode> nodeIndex;
|
|
18 TreeMap<String,String> attributeIndex;
|
|
19
|
99
|
20 public BruteForceTraverser(TreeNode _root) {
|
98
|
21 node = _root;
|
|
22 //pathNodes = this.traverse(_root,new DefaultNodePath(),-1);
|
|
23 }
|
|
24
|
99
|
25 public BruteForceTraverser getTraverser(JungleTree tree) {
|
98
|
26 return new BruteForceTraverser(tree.getRootNode());
|
97
|
27 }
|
|
28
|
98
|
29
|
|
30 /*public IteratorPathNode traverse(TreeNode _node ,NodePath _path ,int _pos){
|
97
|
31
|
|
32 Children children = _node.getChildren();
|
98
|
33 Either<Error,TreeNode> either = children.at(0);
|
|
34 IteratorPathNode list = new IteratorPathNodeImpl();
|
97
|
35 int pathCount = _pos;
|
|
36 if(children.size() == 0){
|
98
|
37 list = list.add(new Pair<TreeNode, NodePath>(node, _path.add(_pos)));
|
97
|
38 return list;
|
|
39 }
|
|
40
|
|
41 for(TreeNode child : children){
|
|
42 list = list.append(traverse(child,_path,pathCount));
|
|
43 pathCount++;
|
|
44 }
|
|
45
|
98
|
46 list = list.add(new Pair<TreeNode,NodePath>(_node, _path.add(_pos)));
|
97
|
47 return list;
|
|
48 }
|
|
49
|
98
|
50 public int count(Query _query, String _key, String _attribute){
|
|
51 return this.find(_query,_key,_attribute);
|
97
|
52 }
|
|
53
|
|
54 public List<Pair<NodePath,TreeNode>> distinct(String _key ,String... _attribute){
|
|
55 return null;
|
|
56 }
|
98
|
57 */
|
99
|
58 public Iterator<Pair<TreeNode, NodePath>> find(final Query query) {
|
|
59 final PathNodeIterator itNode = new PathNodeIterator(node);
|
|
60
|
|
61 return new Iterator<Pair<TreeNode, NodePath>>() {
|
|
62
|
|
63 private Pair<TreeNode,NodePath> matchPair = nextmatch(itNode);
|
|
64
|
|
65 private Pair<TreeNode, NodePath> nextmatch(PathNodeIterator itNode) {
|
|
66 for (;itNode.hasNext();) {
|
|
67 Pair<TreeNode, NodePath> pathNode = itNode.next();
|
|
68 if (query.condition(pathNode.left()))
|
|
69 return pathNode;
|
|
70 }
|
|
71 return null;
|
|
72 }
|
|
73
|
|
74 @Override
|
|
75 public boolean hasNext() {
|
|
76 // TODO Auto-generated method stub
|
|
77 return matchPair != null;
|
|
78 }
|
|
79
|
|
80 @Override
|
|
81 public Pair<TreeNode, NodePath> next() {
|
|
82 Pair<TreeNode,NodePath> currentPair = matchPair;
|
|
83 matchPair = nextmatch(itNode);
|
|
84 return currentPair;
|
|
85 }
|
|
86
|
|
87 @Override
|
|
88 public void remove() {
|
|
89 // TODO Auto-generated method stub
|
|
90
|
|
91 }
|
|
92
|
|
93 };
|
|
94
|
98
|
95 }
|
|
96
|
97
|
97
|
|
98 }
|