org.neo4j.api.core
Interface TraversalPosition


public interface TraversalPosition

Encapsulates information about the current traversal position.


Method Summary
 Node currentNode()
          Return the current node.
 int depth()
          Returns the current traversal depth.
 boolean isStartNode()
          Returns true if the current position is the start node, false otherwise.
 Relationship lastRelationshipTraversed()
          Return the last relationship traversed, may be null.
 boolean notStartNode()
          Returns true if the current position is anywhere except on the start node, false if it is on the start node.
 Node previousNode()
          Returns the previous node, may be null.
 int returnedNodesCount()
          Returns the number of nodes returned by traverser so far.
 

Method Detail

currentNode

Node currentNode()
Return the current node.

Returns:
The current node

previousNode

Node previousNode()
Returns the previous node, may be null.

Returns:
The previous node

lastRelationshipTraversed

Relationship lastRelationshipTraversed()
Return the last relationship traversed, may be null.

Returns:
The last relationship traversed

depth

int depth()
Returns the current traversal depth.

Returns:
The current traversal depth

returnedNodesCount

int returnedNodesCount()
Returns the number of nodes returned by traverser so far.

Returns:
The number of returned nodes.

notStartNode

boolean notStartNode()
Returns true if the current position is anywhere except on the start node, false if it is on the start node. This is useful because code in the evaluators usually have to treat the edge case of the start node separately and using this method makes that code a lot cleaner. For example, old code would be:
 
 public boolean isReturnableNode( TraversalPosition currentPos )
 {
        if ( currentPos.lastRelationshipTraversed() == null )
        {
                return false;
        }
        else
        {
                return currentPos.lastRelationshipTraversed().isType(
                    MyRelationshipTypes.SOME_REL );
        }
 }
 
 
But using notStartNode():
 
 public boolean isReturnableNode( TraversalPosition currentPos )
 {
        return currentPos.notStartNode()
            && currentPos.lastRelationshipTraversed().isType(
                MyRelationshipTypes.SOME_REL );
 }
 
 

Returns:
true if the traversal is not currently positioned on the start node, false if it is

isStartNode

boolean isStartNode()
Returns true if the current position is the start node, false otherwise. This is useful because code in the evaluators usually have to treat the edge case of the start node separately and using this method makes that code a lot cleaner. For example, old code would be:
 
 public boolean isReturnableNode( TraversalPosition currentPos )
 {
      if ( currentPos.lastRelationshipTraversed() == null )
      {
              return false;
      }
      else
      {
              return currentPos.lastRelationshipTraversed().isType(
                  MyRelationshipTypes.SOME_REL );
      }
 }
 
 
But using notStartNode():
 
 public boolean isReturnableNode( TraversalPosition currentPos )
 {
      return !currentPos.isStartNode()
          && currentPos.lastRelationshipTraversed().isType(
              MyRelationshipTypes.SOME_REL );
 }
 
 

Returns:
true if the traversal is on the start node, false otherwise.


Copyright © 2009 Neo4j. All Rights Reserved.