use of org.neo4j.graphdb.Path in project graphdb by neo4j-attic.
the class TestMultipleFilters method testNarrowingFilters.
@Test
public void testNarrowingFilters() {
Evaluator mustBeConnectedToK = new MustBeConnectedToNodeFilter(getNodeWithName("k"));
Evaluator mustNotHaveMoreThanTwoOutRels = new Evaluator() {
public Evaluation evaluate(Path path) {
return Evaluation.ofIncludes(IteratorUtil.count(path.endNode().getRelationships(Direction.OUTGOING)) <= 2);
}
};
TraversalDescription description = Traversal.description().evaluator(mustBeConnectedToK);
expectNodes(description.traverse(referenceNode()), "b", "c");
expectNodes(description.evaluator(mustNotHaveMoreThanTwoOutRels).traverse(referenceNode()), "c");
}
use of org.neo4j.graphdb.Path in project graphdb by neo4j-attic.
the class TestPath method testPathIterator.
@Test
public void testPathIterator() {
Path path = Traversal.description().evaluator(Evaluators.atDepth(4)).traverse(referenceNode()).iterator().next();
assertPathIsCorrect(path);
}
use of org.neo4j.graphdb.Path in project graphdb by neo4j-attic.
the class Traversal method combineSourcePaths.
/**
* Combines two {@link TraversalBranch}s with a common
* {@link TraversalBranch#node() head node} in order to obtain an
* {@link TraversalBranch} representing a path from the start node of the
* <code>source</code> {@link TraversalBranch} to the start node of the
* <code>target</code> {@link TraversalBranch}. The resulting
* {@link TraversalBranch} will not {@link TraversalBranch#next() expand
* further}, and does not provide a {@link TraversalBranch#parent() parent}
* {@link TraversalBranch}.
*
* @param source the {@link TraversalBranch} where the resulting path starts
* @param target the {@link TraversalBranch} where the resulting path ends
* @throws IllegalArgumentException if the {@link TraversalBranch#node()
* head nodes} of the supplied {@link TraversalBranch}s does not
* match
* @return an {@link TraversalBranch} that represents the path from the
* start node of the <code>source</code> {@link TraversalBranch} to
* the start node of the <code>target</code> {@link TraversalBranch}
*/
public static TraversalBranch combineSourcePaths(TraversalBranch source, TraversalBranch target) {
if (!source.node().equals(target.node())) {
throw new IllegalArgumentException("The nodes of the head and tail must match");
}
Path headPath = source.position(), tailPath = target.position();
Relationship[] relationships = new Relationship[headPath.length() + tailPath.length()];
Iterator<Relationship> iter = headPath.relationships().iterator();
for (int i = 0; iter.hasNext(); i++) {
relationships[i] = iter.next();
}
iter = tailPath.relationships().iterator();
for (int i = relationships.length - 1; iter.hasNext(); i--) {
relationships[i] = iter.next();
}
return new FinalTraversalBranch(tailPath.startNode(), relationships);
}
use of org.neo4j.graphdb.Path in project graphdb by neo4j-attic.
the class TreeGraphTest method testDepthFirstTraversalReturnsNodesOnCorrectDepths.
@Test
public void testDepthFirstTraversalReturnsNodesOnCorrectDepths() throws Exception {
Traverser traverser = Traversal.description().depthFirst().traverse(referenceNode());
int i = 0;
for (Path pos : traverser) {
assertEquals(expectedDepth(i++), pos.length());
}
assertEquals(13, i);
}
use of org.neo4j.graphdb.Path in project graphdb by neo4j-attic.
the class TreeGraphTest method pathsIteratorReturnAllNodes.
@Test
public void pathsIteratorReturnAllNodes() throws Exception {
Traverser traverser = Traversal.description().traverse(referenceNode());
int count = 0;
for (Path path : traverser) {
assertNotNull("returned paths should not be null. path #" + count, path);
count++;
}
assertEquals(13, count);
}
Aggregations