Mercurial > hg > Members > tatsuki > bench > jungle-core
diff 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 |
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/traverser/InterfaceTraverser.java Thu Sep 11 03:10:03 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/traverser/InterfaceTraverser.java Thu Sep 11 16:38:26 2014 +0900 @@ -2,96 +2,114 @@ import java.util.Iterator; -import fj.data.List; import fj.data.TreeMap; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.query.PathNodeIterator; -import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.query.Query; +import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.query.SearchQuery; +import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.query.UpdateQuery; public class InterfaceTraverser { InterfaceTraverser traverser; + TreeNode node; - TreeMap<String,TreeNode> nodeIndex; - TreeMap<String,String> attributeIndex; - - public InterfaceTraverser(TreeNode _root) { - node = _root; - //pathNodes = this.traverse(_root,new DefaultNodePath(),-1); + TreeMap<String, TreeNode> nodeIndex; + TreeMap<String, String> attributeIndex; + JungleTreeEditor editor; + + public InterfaceTraverser(TreeNode _root, + Pair<TreeMap<String, TreeNode>, TreeMap<String, String>> index, + JungleTreeEditor editor) { + this.node = _root; + this.nodeIndex = index.left(); + this.attributeIndex = index.right(); + this.editor = editor; } - + public InterfaceTraverser getTraverser(JungleTree tree) { - return new InterfaceTraverser(tree.getRootNode()); + return new InterfaceTraverser(tree.getRootNode(), tree.getIndex(), + tree.getTreeEditor()); } - - /*public IteratorPathNode traverse(TreeNode _node ,NodePath _path ,int _pos){ - - Children children = _node.getChildren(); - Either<Error,TreeNode> either = children.at(0); - IteratorPathNode list = new IteratorPathNodeImpl(); - int pathCount = _pos; - if(children.size() == 0){ - list = list.add(new Pair<TreeNode, NodePath>(node, _path.add(_pos))); - return list; - } - - for(TreeNode child : children){ - list = list.append(traverse(child,_path,pathCount)); - pathCount++; + public void set(TreeNode root){ + this.node = root; + } + /* + * public IteratorPathNode traverse(TreeNode _node ,NodePath _path ,int + * _pos){ + * + * Children children = _node.getChildren(); Either<Error,TreeNode> either = + * children.at(0); IteratorPathNode list = new IteratorPathNodeImpl(); int + * pathCount = _pos; if(children.size() == 0){ list = list.add(new + * Pair<TreeNode, NodePath>(node, _path.add(_pos))); return list; } + * + * for(TreeNode child : children){ list = + * list.append(traverse(child,_path,pathCount)); pathCount++; } + * + * list = list.add(new Pair<TreeNode,NodePath>(_node, _path.add(_pos))); + * return list; } + * + * public int count(Query _query, String _key, String _attribute){ return + * this.find(_query,_key,_attribute); } + * + * public List<Pair<NodePath,TreeNode>> distinct(String _key ,String... + * _attribute){ return null; } + */ + public JungleTreeEditor update(final UpdateQuery query) { + Iterator<Pair<TreeNode, NodePath>> findNode = find(query); + //do { + for (; findNode.hasNext();) { + Either<Error, JungleTreeEditor> either = editor.putAttribute(findNode.next().right(), "KEY", query.getUpdateAttribute()); + if (either.isA()) + ;// wait delay write + editor = either.b(); } - - list = list.add(new Pair<TreeNode,NodePath>(_node, _path.add(_pos))); - return list; - } - - public int count(Query _query, String _key, String _attribute){ - return this.find(_query,_key,_attribute); + //} while (editor.success().isA()); + + return editor; } - - public List<Pair<NodePath,TreeNode>> distinct(String _key ,String... _attribute){ - return null; - } - */ - public Iterator<Pair<TreeNode, NodePath>> find(final Query query) { + + public Iterator<Pair<TreeNode, NodePath>> find(final SearchQuery query) { final PathNodeIterator itNode = new PathNodeIterator(node); - + return new Iterator<Pair<TreeNode, NodePath>>() { - private Pair<TreeNode,NodePath> matchPair = nextmatch(itNode); + private Pair<TreeNode, NodePath> matchPair = nextmatch(itNode); + + private Pair<TreeNode, NodePath> nextmatch(PathNodeIterator itNode) { + for (; itNode.hasNext();) { + Pair<TreeNode, NodePath> pathNode = itNode.next(); + if (query.condition(pathNode.left())) + return pathNode; + } + return null; + } - private Pair<TreeNode, NodePath> nextmatch(PathNodeIterator itNode) { - for (;itNode.hasNext();) { - Pair<TreeNode, NodePath> pathNode = itNode.next(); - if (query.condition(pathNode.left())) - return pathNode; - } - return null; - } - - @Override - public boolean hasNext() { - return matchPair != null; - } + @Override + public boolean hasNext() { + return matchPair != null; + } - @Override - public Pair<TreeNode, NodePath> next() { - Pair<TreeNode,NodePath> currentPair = matchPair; - matchPair = nextmatch(itNode); - return currentPair; - } + @Override + public Pair<TreeNode, NodePath> next() { + Pair<TreeNode, NodePath> currentPair = matchPair; + matchPair = nextmatch(itNode); + return currentPair; + } - @Override - public void remove() { - // TODO Auto-generated method stub - - } + @Override + public void remove() { + // TODO Auto-generated method stub + + } }; } - }