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 neo4j by neo4j.
the class CircularGraphTest method testCircularBug.
@Test
public void testCircularBug() {
final long timestamp = 3;
try (Transaction tx = beginTx()) {
getNodeWithName("2").setProperty("timestamp", 1L);
getNodeWithName("3").setProperty("timestamp", 2L);
tx.success();
}
try (Transaction tx2 = beginTx()) {
final RelationshipType type = RelationshipType.withName("TO");
Iterator<Node> nodes = getGraphDb().traversalDescription().depthFirst().relationships(type, Direction.OUTGOING).evaluator(path -> {
Relationship rel = path.lastRelationship();
boolean relIsOfType = rel != null && rel.isType(type);
boolean prune = relIsOfType && (Long) path.endNode().getProperty("timestamp") >= timestamp;
return Evaluation.of(relIsOfType, !prune);
}).traverse(node("1")).nodes().iterator();
assertEquals("2", nodes.next().getProperty("name"));
assertEquals("3", nodes.next().getProperty("name"));
assertFalse(nodes.hasNext());
}
}
use of org.neo4j.graphdb.Path in project neo4j by neo4j.
the class TestBidirectionalTraversal method ensureCorrectPathEntitiesInShortPath.
@Test
public void ensureCorrectPathEntitiesInShortPath() throws Exception {
/*
* (a)-->(b)
*/
createGraph("a TO b");
Node a = getNodeWithName("a");
Node b = getNodeWithName("b");
Relationship r = a.getSingleRelationship(to, OUTGOING);
Path path = Iterables.single(getGraphDb().bidirectionalTraversalDescription().mirroredSides(getGraphDb().traversalDescription().relationships(to, OUTGOING).uniqueness(NODE_PATH)).collisionEvaluator(Evaluators.atDepth(1)).sideSelector(SideSelectorPolicies.LEVEL, 1).traverse(a, b));
assertContainsInOrder(path.nodes(), a, b);
assertContainsInOrder(path.reverseNodes(), b, a);
assertContainsInOrder(path.relationships(), r);
assertContainsInOrder(path.reverseRelationships(), r);
assertContainsInOrder(path, a, r, b);
assertEquals(a, path.startNode());
assertEquals(b, path.endNode());
assertEquals(r, path.lastRelationship());
}
Aggregations