Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.neo4j.graphdb
Interface TraversalPosition

    public interface TraversalPosition

Encapsulates information about the current traversal position. The TraversalPosition is mainly used in `StopEvaluator.isStopNode(TraversalPosition)` and `ReturnableEvaluator.isReturnableNode(TraversalPosition)` for evaluating whether a position in a traversal is a point where the traversal should stop or if the node at that position is to be part of the result respectively.

Method Summary
`Node` | `currentNode()` Returns 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.
`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.
`int` | `returnedNodesCount()` Returns the number of nodes returned by the traverser so far.

Method Detail

### currentNode

    Node currentNode()

  Returns the current node.

  Returns:
    The current node

### previousNode

    Node previousNode()

  Returns the previous node. If this TraversalPosition represents the start node `null` is returned.

  Returns:
    The previous node, or `null`

### lastRelationshipTraversed

    Relationship lastRelationshipTraversed()

  Return the last relationship traversed. If this TraversalPosition represents the start node `null` is returned.

  Returns:
    The last relationship traversed, or `null`.

### depth

    int depth()

  Returns the current traversal depth. The traversal depth is the length of the path taken to reach the current traversal position. This is not necessarily the length of shortest path from the start node to the node at the current position. When traversing `breadth first` the depth is the length of the shortest path from the start node to the node at the current position, but when traversing `depth first` there might exist shorter paths from the start node to the node at this position.

  Returns:
    The current traversal depth

### returnedNodesCount

    int returnedNodesCount()

  Returns the number of nodes returned by the 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. This allows for much cleaner code where `null` checks can be avoided for return values from `lastRelationshipTraversed()` and `previousNode()`, such as in this example:

       public boolean isStopNode( TraversalPosition currentPos )
       {
           // Stop at nodes reached through a SOME_RELATIONSHIP.
           return currentPos.notStartNode()
               && currentPos.lastRelationshipTraversed().isType(
                   MyRelationshipTypes.SOME_RELATIONSHIP );
       }

  Returns:
    `true` if the this TraversalPosition is not at 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. This allows for much cleaner code where `null` checks can be avoided for return values from `lastRelationshipTraversed()` and `previousNode()`, such as in this example:

       public boolean isReturnableNode( TraversalPosition currentPos )
       {
           // The start node, and nodes reached through SOME_RELATIONSHIP
           // are returnable.
           return currentPos.isStartNode()
               || currentPos.lastRelationshipTraversed().isType(
                   MyRelationshipTypes.SOME_RELATIONSHIP );
       }

  Returns:
    `true` if the this TraversalPosition is at the start node, `false` if it is not.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2010 Neo4j. All Rights Reserved.