Mercurial > hg > Members > shoshi > jungle > jungle-core
changeset 136:0f68cd7b2838
add Node Search
author | one |
---|---|
date | Sat, 25 Oct 2014 16:50:32 +0900 |
parents | 6e9a8d26e0cf |
children | 7334f78a92c3 |
files | src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/traverser/InterfaceTraverser.java |
diffstat | 1 files changed, 53 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/traverser/InterfaceTraverser.java Fri Oct 24 18:49:48 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/traverser/InterfaceTraverser.java Sat Oct 25 16:50:32 2014 +0900 @@ -71,7 +71,59 @@ - public Iterator<Pair<TreeNode, NodePath>> find(Query query, String key, String searchValue) { + public Iterator<Pair<TreeNode, NodePath>> find(Query query, TreeNode searchNode, String key, String searchValue) { + + final PathNodeIterator itNode = new PathNodeIterator(searchNode); + return new Iterator<Pair<TreeNode, NodePath>>() { + + 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; + } + + @Override + public boolean hasNext() { + if (matchPair == null) { +// index = itNode.getIndex(); + return false; + } + return true; + } + + @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 + + } + + }; + + } + + public Iterator<Pair<TreeNode, NodePath>> find(Query query) { + return find(query, node, null, null); + } + + public Iterator<Pair<TreeNode, NodePath>> find(Query query, TreeNode searchNode) { + return find(query, searchNode, null, null); + } + + public Iterator<Pair<TreeNode, NodePath>> find(Query query, String key, String searchValue) { if (index.get(key).isSome()) {