You can do something like the following. The idea is to traverse but only continue to expand down the path if the properties of the current node match the sequence of values. I haven't tested the code below, so assume typos and missing ;
Node r = db.getNodeById(0);
String[] sequence = {"aaa","bbb","ccc"};
Traverser traverser = Traversal.description()
.depthFirst()
.expand(new ArrayExpander(sequence))
.evaluator(Evaluators.atDepth(sequence.length()))
.uniqueness(Uniqueness.NONE)
.traverse(r);
for ( org.neo4j.graphdb.Path p : traverser )
{
//do something with the nodes accessible by p.nodes()
}
The path expander looks something like:
public class ArrayExpander implements PathExpander {
private String[] sequence;
public ArrayExpander(String[] sequence)
{
this.sequence = sequence;
}
public Iterable<Relationship> expand(Path path, BranchState state){
if(path.endNode().getProperty("n").equals(sequence[path.length()]){
return path.endNode().getRelationships(Direction.INCOMING);
} else {
return path.endNode().getRelationships(DynamicRelationshipType.withName("IDONTEXIST"));
}
}
public ArrayExpander reverse()
{
return new ArrayExpander(Collections.reverse(Arrays.asList(sequence)));
}
}