public interface TraversalPosition
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.Modifier and Type | Method and Description |
---|---|
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.
|
Node currentNode()
Node previousNode()
null
is
returned.null
Relationship lastRelationshipTraversed()
null
is
returned.null
.int depth()
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.int returnedNodesCount()
boolean notStartNode()
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
);
}
true
if the this TraversalPosition is not at the
start node, false
if it is.boolean isStartNode()
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
);
}
true
if the this TraversalPosition is at the start
node, false
if it is not.Copyright © 2002–2014 The Neo4j Graph Database Project. All rights reserved.