use of org.apache.tinkerpop.gremlin.process.traversal.step.branch.UnionStep in project unipop by unipop-graph.
the class UniGraphUnionStepStrategy method apply.
@Override
public void apply(Traversal.Admin<?, ?> traversal) {
Graph graph = traversal.getGraph().get();
if (!(graph instanceof UniGraph)) {
return;
}
UniGraph uniGraph = (UniGraph) graph;
TraversalHelper.getStepsOfClass(UnionStep.class, traversal).forEach(unionStep -> {
Traversal.Admin[] traversals = (Traversal.Admin[]) unionStep.getGlobalChildren().toArray(new Traversal.Admin[0]);
for (Traversal.Admin admin : traversals) {
if (TraversalHelper.getLastStepOfAssignableClass(ReducingBarrierStep.class, admin).isPresent() || traversal.getParent() instanceof RepeatStep)
return;
}
UniGraphUnionStep uniGraphUnionStep = new UniGraphUnionStep(traversal, uniGraph, traversals);
if (TraversalHelper.stepIndex(unionStep, traversal) != -1) {
TraversalHelper.replaceStep(unionStep, uniGraphUnionStep, traversal);
} else {
TraversalHelper.getStepsOfAssignableClass(TraversalParent.class, traversal).forEach(traversalParent -> {
traversalParent.getLocalChildren().forEach(child -> {
if (TraversalHelper.stepIndex(unionStep, child) != -1) {
TraversalHelper.replaceStep(unionStep, uniGraphUnionStep, child);
}
});
traversalParent.getGlobalChildren().forEach(child -> {
if (TraversalHelper.stepIndex(unionStep, child) != -1) {
TraversalHelper.replaceStep(unionStep, uniGraphUnionStep, child);
}
});
});
}
});
}
Aggregations