Mercurial > hg > Members > shoshi > jungle > jungle-core
changeset 262:741297b630f8 Implementation_of_communication
changed name PathNodeIterator to JungleNodeIterator
author | tatsuki |
---|---|
date | Wed, 30 Nov 2016 19:47:47 +0900 |
parents | 55df1607dc0b |
children | cac88cf813f1 |
files | src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/query/JungleNodeIterator.java src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/query/PathNodeIterator.java src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/omnigraffle/InsertNodePositionData.java src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/traverser/InterfaceTraverser.java |
diffstat | 4 files changed, 88 insertions(+), 88 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/query/JungleNodeIterator.java Wed Nov 30 19:47:47 2016 +0900 @@ -0,0 +1,80 @@ +package jp.ac.u_ryukyu.ie.cr.jungle.query; + +import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.TreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.TreeNodeChildren; + +import java.util.Iterator; +import java.util.Stack; + +public class JungleNodeIterator implements Iterator<TreeNode> { + + TreeNode root; + TreeNode node; + int childNumber; + private TreeNodeChildren children; + private Stack<TreeNode> nodeStack = new Stack<>(); + private Stack<Integer> searchStack = new Stack<>(); + + /* + * get queryIndexCondition from query + * if already index exists, use index + * otherwise traverse tree and create index + * + * */ + public JungleNodeIterator(TreeNode root) { + this.root = root; + this.node = root; + } + + @Override + public boolean hasNext() { + return node != null; + } + + @Override + public TreeNode next() { + TreeNode now = node; + if (node.getChildren().size() > 0) { + nodeStack.push(node); + children = node.getChildren(); + node = children.at(0).b(); + childNumber = 1; + searchStack.push(childNumber); + } else if (node == root) { + node = null; // no more node + children = null; + return now; + }else if (children != null && children.size() > childNumber) { + childNumber = searchStack.pop(); + node = children.at(childNumber).b(); + searchStack.push(++childNumber); + } else { + node = nodeStack.pop(); + children = node.getChildren(); + childNumber = searchStack.pop(); + for (; children.size() == childNumber;) { + if (node == root) { + node = null; // no more node + children = null; + return now; + } + node = nodeStack.pop(); + children = node.getChildren(); + childNumber = searchStack.pop(); + } + if (node != null && childNumber < children.size()) { + nodeStack.push(node); + node = children.at(childNumber).b(); + searchStack.push(++childNumber); + } + } + return now; + } + + @Override + public void remove() { + // TODO Auto-generated method stub + + } + +}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/query/PathNodeIterator.java Sat Nov 19 22:43:28 2016 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,80 +0,0 @@ -package jp.ac.u_ryukyu.ie.cr.jungle.query; - -import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.TreeNode; -import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.TreeNodeChildren; - -import java.util.Iterator; -import java.util.Stack; - -public class PathNodeIterator implements Iterator<TreeNode> { - - TreeNode root; - TreeNode node; - int childNumber; - private TreeNodeChildren children; - private Stack<TreeNode> nodeStack = new Stack<>(); - private Stack<Integer> searchStack = new Stack<>(); - - /* - * get queryIndexCondition from query - * if already index exists, use index - * otherwise traverse tree and create index - * - * */ - public PathNodeIterator(TreeNode root) { - this.root = root; - this.node = root; - } - - @Override - public boolean hasNext() { - return node != null; - } - - @Override - public TreeNode next() { - TreeNode now = node; - if (node.getChildren().size() > 0) { - nodeStack.push(node); - children = node.getChildren(); - node = children.at(0).b(); - childNumber = 1; - searchStack.push(childNumber); - } else if (node == root) { - node = null; // no more node - children = null; - return now; - }else if (children != null && children.size() > childNumber) { - childNumber = searchStack.pop(); - node = children.at(childNumber).b(); - searchStack.push(++childNumber); - } else { - node = nodeStack.pop(); - children = node.getChildren(); - childNumber = searchStack.pop(); - for (; children.size() == childNumber;) { - if (node == root) { - node = null; // no more node - children = null; - return now; - } - node = nodeStack.pop(); - children = node.getChildren(); - childNumber = searchStack.pop(); - } - if (node != null && childNumber < children.size()) { - nodeStack.push(node); - node = children.at(childNumber).b(); - searchStack.push(++childNumber); - } - } - return now; - } - - @Override - public void remove() { - // TODO Auto-generated method stub - - } - -}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/omnigraffle/InsertNodePositionData.java Sat Nov 19 22:43:28 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/omnigraffle/InsertNodePositionData.java Wed Nov 30 19:47:47 2016 +0900 @@ -1,7 +1,7 @@ package jp.ac.u_ryukyu.ie.cr.jungle.store.omnigraffle; import jp.ac.u_ryukyu.ie.cr.jungle.JungleTree; -import jp.ac.u_ryukyu.ie.cr.jungle.query.PathNodeIterator; +import jp.ac.u_ryukyu.ie.cr.jungle.query.JungleNodeIterator; import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.TreeNode; import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.TreeNodeChildren; import jp.ac.u_ryukyu.ie.cr.jungle.store.index.ParentIndex; @@ -42,7 +42,7 @@ public TreeMap<TreeNode, NodePoint> InsertPositionData() { ParentIndex parentIndex = tree.getParentIndex(); TreeNode rootNode = tree.getRootNode(); - PathNodeIterator nodeIterator = new PathNodeIterator(rootNode); + JungleNodeIterator nodeIterator = new JungleNodeIterator(rootNode); NodePoint rootPoint = new NodePoint(); //まずはrootのY座標を指定する、Y座標を指定する際は親Nodeを参照するため、rootだけは別に処理を書く必要がある rootPoint.setY(NODE_Y_GAP);
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/traverser/InterfaceTraverser.java Sat Nov 19 22:43:28 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/traverser/InterfaceTraverser.java Wed Nov 30 19:47:47 2016 +0900 @@ -3,7 +3,7 @@ import jp.ac.u_ryukyu.ie.cr.jungle.store.NulIterator; import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.TreeNode; import jp.ac.u_ryukyu.ie.cr.jungle.data.list.List; -import jp.ac.u_ryukyu.ie.cr.jungle.query.PathNodeIterator; +import jp.ac.u_ryukyu.ie.cr.jungle.query.JungleNodeIterator; import jp.ac.u_ryukyu.ie.cr.jungle.query.Query; import jp.ac.u_ryukyu.ie.cr.jungle.store.index.IndexCreater; import jp.ac.u_ryukyu.ie.cr.jungle.store.index.ParentIndex; @@ -24,8 +24,7 @@ this(root, new TreeMap<>(), new ParentIndex(), indexFlag); } - public InterfaceTraverser(TreeNode root, TreeMap<String, TreeMap<String, List<TreeNode>>> index, - ParentIndex parentIndex, boolean useIndex) { + public InterfaceTraverser(TreeNode root, TreeMap<String, TreeMap<String, List<TreeNode>>> index, ParentIndex parentIndex, boolean useIndex) { this.root = root; this.indexList = index; this.parentIndex = parentIndex; @@ -65,7 +64,7 @@ } public Iterator<TreeNode> find(final Query query) { - return find(query,null,null); + return find(query, null, null); } public Iterator<TreeNode> find(final Query query, final String key, String searchValue) { @@ -75,7 +74,7 @@ nodeIterator = get(key, searchValue); ; } else { - nodeIterator = new PathNodeIterator(root); + nodeIterator = new JungleNodeIterator(root); } TreeNode firstMatchNode = null; @@ -124,7 +123,8 @@ if (!indexOp.isPresent()) return null; - Optional<List<TreeNode>> nodeListOp = indexOp.get().get(value); + TreeMap<String, List<TreeNode>> index = indexOp.get(); + Optional<List<TreeNode>> nodeListOp = index.get(value); if (!nodeListOp.isPresent()) return new NulIterator<TreeNode>();