use of org.neo4j.graphdb.PathExpanders.forTypeAndDirection in project neo4j by neo4j.
the class TestShortestPath method filtersTouchesAllIntermediateNodes.
@Test
void filtersTouchesAllIntermediateNodes() {
//
try (Transaction transaction = graphDb.beginTx()) {
graph.makeEdgeChain(transaction, "a,b,c,d");
final Node a = graph.getNode(transaction, "a");
final Node d = graph.getNode(transaction, "d");
Collection<Node> touchedByFilter = new HashSet<>();
final Predicate<Node> filter = item -> {
touchedByFilter.add(item);
return true;
};
final PathExpander expander = PathExpanderBuilder.empty().add(R1, OUTGOING).addNodeFilter(filter).build();
// final PathExpander expander = ((StandardExpander) PathExpanders.forTypeAndDirection(R1, OUTGOING)).addNodeFilter( filter );
var context = new BasicEvaluationContext(transaction, graphDb);
Path path = Iterables.single(shortestPath(context, expander, 10).findAllPaths(a, d));
assertEquals(3, path.length());
List<Node> nodes = Iterables.asList(path.nodes());
List<Node> intermediateNodes = nodes.subList(1, nodes.size() - 1);
assertTrue(touchedByFilter.containsAll(intermediateNodes), "touchedByFilter: " + touchedByFilter);
assertFalse(touchedByFilter.contains(a));
assertFalse(touchedByFilter.contains(d));
transaction.commit();
}
}
Aggregations