view src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/query/IteratorPathNodeImpl.java @ 98:95000ff9064d

Create Query
author one
date Tue, 09 Sep 2014 16:23:01 +0900
parents
children
line wrap: on
line source

package jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.query;

import java.util.Stack;

import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath;
import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath;
import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode;
import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair;

public class IteratorPathNodeImpl implements IteratorPathNode {

	Stack<Pair<TreeNode, NodePath>> pathNodeStack = new Stack<Pair<TreeNode, NodePath>>();
	public IteratorPathNodeImpl(TreeNode _root){
		pathNodeStack.push(new Pair<TreeNode, NodePath>(_root, new DefaultNodePath()));
	}


	@Override
	public boolean hasNext() {
		if(pathNodeStack.empty())
			return false;
		return true;
	}

	@Override
	public Pair<TreeNode, NodePath> next() {
		Pair<TreeNode, NodePath> pathNode = pathNodeStack.pop();
		if(pathNode.left().getChildren().size() == 0)
			return pathNode;
		int count = 0;
		for(TreeNode child : pathNode.left().getChildren()){
			pathNodeStack.push(new Pair<TreeNode,NodePath>(child,pathNode.right().add(count)));
			count++;
		}
		return pathNode;
	}
	
}