/*
 * Copyright 2002-2007 Network Engine for Objects in Lund AB [neotechnology.com]
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.neo4j.impl.traversal;

import org.neo4j.api.core.Node;
import org.neo4j.api.core.Relationship;
import org.neo4j.api.core.TraversalPosition;
import org.neo4j.impl.core.NodeManager;

class TraversalPositionImpl implements TraversalPosition
{
	private static NodeManager nodeManager = NodeManager.getManager();
	
	private Node				currentNode			= null;
	private Node				previousNode		= null;
	private Relationship		lastRelTraversed	= null;
	private int					currentDepth		= -1;
	private int					returnedNodesCount	= -1;

	TraversalPositionImpl(
						Node currentNode,
						Node previousNode,
						Relationship lastRelTraversed,
						int currentDepth
					 )
	{
		this.currentNode = currentNode;
		this.previousNode = previousNode;
		this.lastRelTraversed = lastRelTraversed;
		this.currentDepth = currentDepth;
	}
	
	void setReturnedNodesCount( int returnedNodesCount )
	{
		this.returnedNodesCount = returnedNodesCount;
	}
	
	public Node currentNode()
	{
		return this.currentNode;
	}
	
	public Node previousNode()
	{
		return this.previousNode;
	}
	
	public Relationship lastRelationshipTraversed()
	{
		return this.lastRelTraversed;
	}
	
	public int depth()
	{
		return this.currentDepth;
	}
	
	public int returnedNodesCount()
	{
		return this.returnedNodesCount;
	}

	public boolean notStartNode()
    {
	    return this.depth() > 0;
    }
	
	boolean isValid()
	{
		if ( lastRelTraversed == null )
		{
			return true;
		}
		return nodeManager.isValidRelationship( lastRelTraversed );
	}
}
