private TraversalDescription traversalDescription(GraphDatabaseService db) { return db.traversalDescription() .breadthFirst() .uniqueness(NODE_GLOBAL) .relationships(withName("FRIEND")) .evaluator( new Evaluator() { @Override public Evaluation evaluate(Path path) { if (path.length() == 4) { return Evaluation.INCLUDE_AND_PRUNE; } return Evaluation.EXCLUDE_AND_CONTINUE; } }); }
public Iterable<Node> getFriends(String name) { ResourceIterable<Node> users = db.findNodesByLabelAndProperty(USER, "name", name); Node startNode = IteratorUtil.single(users); return traversalDescription.traverse(startNode).nodes(); }