Fix depth-frist TRAVERSE with multiple entry points
returned the entry points in reverse order, now it returns them in the order they are provided
@@ -44,10 +44,10 @@ public class DepthFirstTraverseStep extends AbstractTraverseStep {
((OResultInternal) item).setMetadata("$path", path);
if (item.isElement() && !traversed.contains(item.getElement().get().getIdentity())) {
- tryAddEntryPoint(item, ctx);
+ tryAddEntryPointAtTheEnd(item, ctx);
traversed.add(item.getElement().get().getIdentity());
} else if (item.getProperty("@rid") != null && item.getProperty("@rid") instanceof OIdentifiable) {
- tryAddEntryPoint(item, ctx);
+ tryAddEntryPointAtTheEnd(item, ctx);
traversed.add(((OIdentifiable) item.getProperty("@rid")).getIdentity());
}
}
@@ -197,6 +197,18 @@ public class DepthFirstTraverseStep extends AbstractTraverseStep {
}
}
+ private void tryAddEntryPointAtTheEnd(OResult res, OCommandContext ctx) {
+ if (whileClause == null || whileClause.matchesFilters(res, ctx)) {
+ this.entryPoints.add(res);
+ }
+
+ if (res.isElement()) {
+ traversed.add(res.getElement().get().getIdentity());
+ } else if (res.getProperty("@rid") != null && res.getProperty("@rid") instanceof OIdentifiable) {
+ traversed.add(((OIdentifiable) res.getProperty("@rid")).getIdentity());
+ }
+ }
+
@Override
public String prettyPrint(int depth, int indent) {
String spaces = OExecutionStepInternal.getIndent(depth, indent);
