Node
. Also because of the introduction of a new traversal framework
and the usage of it. The new way of doing traversals is by creating a
new TraversalDescription
from
Traversal.description()
, add rules and
behaviours to it and then calling
TraversalDescription.traverse(Node...)
.public interface Traverser extends Iterable<Node>
Iterable
that
encapsulates a number of traversal parameters (defined at traverser creation)
and returns an iterator of nodes that match those parameters. It is created
by invoking Node.traverse(...)
. Upon creation, the
traverser is positioned at the start node, but it doesn't actually start
traversing until its iterator().next()
method is invoked
and will then traverse lazily one step each time next
is called.
When a Traverser is created it is parameterized with two evaluators and the
relationship types to traverse, with the direction to traverse each type in.
The evaluators are used for determining for each node in the set of candidate
nodes if it should be returned or not, and if the traversal should be pruned
(stopped) at this point. The nodes that are traversed by a Traverser are each
visited exactly once, meaning that the returned iterator of nodes will never
contain duplicate nodes. This also means that the traversed relationships
will form a spanning tree over the traversed nodes, with the side effect that
some internal relationships between nodes in the traversal are not traversed
(and hence not visible in the evaluators
).
Typically a Traverser is used in a for-each loop as follows:
Traverser friends = node.traverse
( Order.BREADTH_FIRST
,
StopEvaluator.END_OF_GRAPH
, ReturnableEvaluator.ALL_BUT_START_NODE
,
MyRelationshipTypes.KNOWS
, Direction.OUTGOING
);
for ( Node
friend : friends )
{
// ...
}
Relationships are equally well traversed regardless of their direction,
performance-wise.Modifier and Type | Interface and Description |
---|---|
static class |
Traverser.Order
Deprecated.
Defines a traversal order as used by the traversal framework.
|
Modifier and Type | Method and Description |
---|---|
TraversalPosition |
currentPosition()
Deprecated.
Returns the current traversal position, that is where the traversal is at
the moment.
|
Collection<Node> |
getAllNodes()
Deprecated.
Returns a collection of all nodes for this traversal.
|
Iterator<Node> |
iterator()
Deprecated.
Returns an
Iterator representing the traversal of the graph. |
TraversalPosition currentPosition()
Traverser traverser = node.traverse
( ... );
for ( Node
node : traverser )
{
TraversalPosition
currentPosition = traverser.currentPosition();
// Get "current position" information right here.
}
Collection<Node> getAllNodes()
hasNext()
for the iterator()
will return false
.Copyright © 2002-2013 The Neo4j Graph Database Project. All Rights Reserved.