Mercurial > hg > Members > tatsuki > bench > jungle-core
comparison src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/traverser/InterfaceTraverser.java @ 101:c297f0015d9e
create Update query
author | one |
---|---|
date | Thu, 11 Sep 2014 16:38:26 +0900 |
parents | 9a7b7af838e0 |
children | 3d88bad21bc4 bed3afd5c2e2 |
comparison
equal
deleted
inserted
replaced
100:9a7b7af838e0 | 101:c297f0015d9e |
---|---|
1 package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser; | 1 package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser; |
2 | 2 |
3 import java.util.Iterator; | 3 import java.util.Iterator; |
4 | 4 |
5 import fj.data.List; | |
6 import fj.data.TreeMap; | 5 import fj.data.TreeMap; |
7 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree; | 6 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree; |
7 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; | |
8 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; | 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; | 9 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; |
10 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; | |
11 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; | |
10 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; | 12 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; |
11 import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.query.PathNodeIterator; | 13 import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.query.PathNodeIterator; |
12 import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.query.Query; | 14 import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.query.SearchQuery; |
15 import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.query.UpdateQuery; | |
13 | 16 |
14 public class InterfaceTraverser { | 17 public class InterfaceTraverser { |
15 InterfaceTraverser traverser; | 18 InterfaceTraverser traverser; |
19 | |
16 TreeNode node; | 20 TreeNode node; |
17 TreeMap<String,TreeNode> nodeIndex; | 21 TreeMap<String, TreeNode> nodeIndex; |
18 TreeMap<String,String> attributeIndex; | 22 TreeMap<String, String> attributeIndex; |
19 | 23 JungleTreeEditor editor; |
20 public InterfaceTraverser(TreeNode _root) { | 24 |
21 node = _root; | 25 public InterfaceTraverser(TreeNode _root, |
22 //pathNodes = this.traverse(_root,new DefaultNodePath(),-1); | 26 Pair<TreeMap<String, TreeNode>, TreeMap<String, String>> index, |
27 JungleTreeEditor editor) { | |
28 this.node = _root; | |
29 this.nodeIndex = index.left(); | |
30 this.attributeIndex = index.right(); | |
31 this.editor = editor; | |
23 } | 32 } |
24 | 33 |
25 public InterfaceTraverser getTraverser(JungleTree tree) { | 34 public InterfaceTraverser getTraverser(JungleTree tree) { |
26 return new InterfaceTraverser(tree.getRootNode()); | 35 return new InterfaceTraverser(tree.getRootNode(), tree.getIndex(), |
36 tree.getTreeEditor()); | |
27 } | 37 } |
28 | |
29 | 38 |
30 /*public IteratorPathNode traverse(TreeNode _node ,NodePath _path ,int _pos){ | 39 public void set(TreeNode root){ |
31 | 40 this.node = root; |
32 Children children = _node.getChildren(); | 41 } |
33 Either<Error,TreeNode> either = children.at(0); | 42 /* |
34 IteratorPathNode list = new IteratorPathNodeImpl(); | 43 * public IteratorPathNode traverse(TreeNode _node ,NodePath _path ,int |
35 int pathCount = _pos; | 44 * _pos){ |
36 if(children.size() == 0){ | 45 * |
37 list = list.add(new Pair<TreeNode, NodePath>(node, _path.add(_pos))); | 46 * Children children = _node.getChildren(); Either<Error,TreeNode> either = |
38 return list; | 47 * children.at(0); IteratorPathNode list = new IteratorPathNodeImpl(); int |
39 } | 48 * pathCount = _pos; if(children.size() == 0){ list = list.add(new |
40 | 49 * Pair<TreeNode, NodePath>(node, _path.add(_pos))); return list; } |
41 for(TreeNode child : children){ | 50 * |
42 list = list.append(traverse(child,_path,pathCount)); | 51 * for(TreeNode child : children){ list = |
43 pathCount++; | 52 * list.append(traverse(child,_path,pathCount)); pathCount++; } |
53 * | |
54 * list = list.add(new Pair<TreeNode,NodePath>(_node, _path.add(_pos))); | |
55 * return list; } | |
56 * | |
57 * public int count(Query _query, String _key, String _attribute){ return | |
58 * this.find(_query,_key,_attribute); } | |
59 * | |
60 * public List<Pair<NodePath,TreeNode>> distinct(String _key ,String... | |
61 * _attribute){ return null; } | |
62 */ | |
63 public JungleTreeEditor update(final UpdateQuery query) { | |
64 Iterator<Pair<TreeNode, NodePath>> findNode = find(query); | |
65 //do { | |
66 for (; findNode.hasNext();) { | |
67 Either<Error, JungleTreeEditor> either = editor.putAttribute(findNode.next().right(), "KEY", query.getUpdateAttribute()); | |
68 if (either.isA()) | |
69 ;// wait delay write | |
70 editor = either.b(); | |
44 } | 71 } |
45 | 72 //} while (editor.success().isA()); |
46 list = list.add(new Pair<TreeNode,NodePath>(_node, _path.add(_pos))); | 73 |
47 return list; | 74 return editor; |
48 } | 75 } |
49 | 76 |
50 public int count(Query _query, String _key, String _attribute){ | 77 public Iterator<Pair<TreeNode, NodePath>> find(final SearchQuery query) { |
51 return this.find(_query,_key,_attribute); | |
52 } | |
53 | |
54 public List<Pair<NodePath,TreeNode>> distinct(String _key ,String... _attribute){ | |
55 return null; | |
56 } | |
57 */ | |
58 public Iterator<Pair<TreeNode, NodePath>> find(final Query query) { | |
59 final PathNodeIterator itNode = new PathNodeIterator(node); | 78 final PathNodeIterator itNode = new PathNodeIterator(node); |
60 | 79 |
61 return new Iterator<Pair<TreeNode, NodePath>>() { | 80 return new Iterator<Pair<TreeNode, NodePath>>() { |
62 | 81 |
63 private Pair<TreeNode,NodePath> matchPair = nextmatch(itNode); | 82 private Pair<TreeNode, NodePath> matchPair = nextmatch(itNode); |
64 | 83 |
65 private Pair<TreeNode, NodePath> nextmatch(PathNodeIterator itNode) { | 84 private Pair<TreeNode, NodePath> nextmatch(PathNodeIterator itNode) { |
66 for (;itNode.hasNext();) { | 85 for (; itNode.hasNext();) { |
67 Pair<TreeNode, NodePath> pathNode = itNode.next(); | 86 Pair<TreeNode, NodePath> pathNode = itNode.next(); |
68 if (query.condition(pathNode.left())) | 87 if (query.condition(pathNode.left())) |
69 return pathNode; | 88 return pathNode; |
70 } | 89 } |
71 return null; | 90 return null; |
72 } | 91 } |
73 | |
74 @Override | |
75 public boolean hasNext() { | |
76 return matchPair != null; | |
77 } | |
78 | 92 |
79 @Override | 93 @Override |
80 public Pair<TreeNode, NodePath> next() { | 94 public boolean hasNext() { |
81 Pair<TreeNode,NodePath> currentPair = matchPair; | 95 return matchPair != null; |
82 matchPair = nextmatch(itNode); | 96 } |
83 return currentPair; | |
84 } | |
85 | 97 |
86 @Override | 98 @Override |
87 public void remove() { | 99 public Pair<TreeNode, NodePath> next() { |
88 // TODO Auto-generated method stub | 100 Pair<TreeNode, NodePath> currentPair = matchPair; |
89 | 101 matchPair = nextmatch(itNode); |
90 } | 102 return currentPair; |
103 } | |
104 | |
105 @Override | |
106 public void remove() { | |
107 // TODO Auto-generated method stub | |
108 | |
109 } | |
91 | 110 |
92 }; | 111 }; |
93 | 112 |
94 } | 113 } |
95 | |
96 | 114 |
97 } | 115 } |