use of org.unipop.structure.UniGraph 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);
}
});
});
}
});
}
use of org.unipop.structure.UniGraph in project unipop by unipop-graph.
the class EdgeStepsStrategy method apply.
@Override
public void apply(Traversal.Admin<?, ?> traversal) {
UniGraph uniGraph = ((UniGraph) traversal.getGraph().get());
TraversalHelper.getStepsOfClass(EdgeOtherVertexStep.class, traversal).forEach(edgeOtherVertexStep -> {
UniGraphEdgeOtherVertexStep uniGraphEdgeOtherVertexStep = new UniGraphEdgeOtherVertexStep(traversal, uniGraph, uniGraph.getControllerManager());
edgeOtherVertexStep.getLabels().forEach(uniGraphEdgeOtherVertexStep::addLabel);
TraversalHelper.replaceStep(edgeOtherVertexStep, uniGraphEdgeOtherVertexStep, traversal);
});
TraversalHelper.getStepsOfClass(EdgeVertexStep.class, traversal).forEach(edgeVertexStep -> {
UniGraphEdgeVertexStep uniGraphEdgeVertexStep = new UniGraphEdgeVertexStep(traversal, edgeVertexStep.getDirection(), uniGraph, uniGraph.getControllerManager());
edgeVertexStep.getLabels().forEach(uniGraphEdgeVertexStep::addLabel);
TraversalHelper.replaceStep(edgeVertexStep, uniGraphEdgeVertexStep, traversal);
});
}
use of org.unipop.structure.UniGraph in project unipop by unipop-graph.
the class UniGraphStepStrategy method apply.
@Override
public void apply(Traversal.Admin<?, ?> traversal) {
if (TraversalHelper.onGraphComputer(traversal))
return;
Graph graph = traversal.getGraph().get();
if (!(graph instanceof UniGraph)) {
return;
}
UniGraph uniGraph = (UniGraph) graph;
TraversalHelper.getStepsOfClass(GraphStep.class, traversal).forEach(graphStep -> {
final UniGraphStep<?, ?> uniGraphStep = new UniGraphStep<>(graphStep, uniGraph.getControllerManager());
TraversalHelper.replaceStep(graphStep, uniGraphStep, traversal);
PredicatesUtil.collectPredicates(uniGraphStep, traversal);
});
}
use of org.unipop.structure.UniGraph in project unipop by unipop-graph.
the class UniGraphRepeatStepStrategy method apply.
@Override
public void apply(Traversal.Admin<?, ?> traversal) {
if (TraversalHelper.onGraphComputer(traversal))
return;
Graph graph = traversal.getGraph().get();
if (!(graph instanceof UniGraph)) {
return;
}
UniGraph uniGraph = (UniGraph) graph;
TraversalHelper.getStepsOfClass(RepeatStep.class, traversal).forEach(repeatStep -> {
if (TraversalHelper.hasStepOfClass(UnionStep.class, (Traversal.Admin) repeatStep.getGlobalChildren().get(0))) {
return;
}
UniGraphRepeatStep uniGraphRepeatStep = new UniGraphRepeatStep(repeatStep, traversal.asAdmin(), uniGraph);
if (repeatStep.getUntilTraversal() != null && TraversalHelper.getFirstStepOfAssignableClass(ReducingBarrierStep.class, repeatStep.getUntilTraversal()).isPresent())
return;
Traversal.Admin<?, ?> repeatTraversal = uniGraphRepeatStep.getRepeatTraversal();
TraversalHelper.replaceStep(repeatStep, uniGraphRepeatStep, traversal);
TraversalHelper.getStepsOfClass(RepeatStep.RepeatEndStep.class, repeatTraversal).forEach(repeatEndStep -> {
UniGraphRepeatStep.RepeatEndStep uniGraphRepeatEndStep = new UniGraphRepeatStep.RepeatEndStep(repeatTraversal, uniGraphRepeatStep);
TraversalHelper.replaceStep(repeatEndStep, uniGraphRepeatEndStep, repeatTraversal);
});
});
}
use of org.unipop.structure.UniGraph in project unipop by unipop-graph.
the class UniGraphVertexStepStrategy method apply.
@Override
public void apply(Traversal.Admin<?, ?> traversal) {
if (TraversalHelper.onGraphComputer(traversal))
return;
Graph graph = traversal.getGraph().get();
if (!(graph instanceof UniGraph)) {
return;
}
UniGraph uniGraph = (UniGraph) graph;
TraversalHelper.getStepsOfAssignableClassRecursively(VertexStep.class, traversal).forEach(vertexStep -> {
if (TraversalHelper.stepIndex(vertexStep, traversal) != -1) {
UniGraphVertexStep uniGraphVertexStep = new UniGraphVertexStep<>(vertexStep, uniGraph, uniGraph.getControllerManager());
TraversalHelper.replaceStep(vertexStep, uniGraphVertexStep, traversal);
if (vertexStep.returnsEdge())
PredicatesUtil.collectPredicates(uniGraphVertexStep, traversal);
} else {
TraversalHelper.getStepsOfAssignableClass(TraversalParent.class, traversal).forEach(traversalParent -> {
traversalParent.getLocalChildren().forEach(child -> {
if (TraversalHelper.stepIndex(vertexStep, child) != -1) {
UniGraphVertexStep uniGraphVertexStep = new UniGraphVertexStep<>(vertexStep, uniGraph, uniGraph.getControllerManager());
TraversalHelper.replaceStep(vertexStep, uniGraphVertexStep, child);
if (vertexStep.returnsEdge())
PredicatesUtil.collectPredicates(uniGraphVertexStep, child);
}
});
traversalParent.getGlobalChildren().forEach(child -> {
if (TraversalHelper.stepIndex(vertexStep, child) != -1) {
UniGraphVertexStep uniGraphVertexStep = new UniGraphVertexStep<>(vertexStep, uniGraph, uniGraph.getControllerManager());
TraversalHelper.replaceStep(vertexStep, uniGraphVertexStep, child);
if (vertexStep.returnsEdge())
PredicatesUtil.collectPredicates(uniGraphVertexStep, child);
} else if (TraversalHelper.hasStepOfAssignableClass(TraversalParent.class, child)) {
TraversalHelper.getStepsOfAssignableClass(TraversalParent.class, child).forEach(traversalParent1 -> {
traversalParent.getLocalChildren().forEach(child1 -> {
if (TraversalHelper.stepIndex(vertexStep, child1) != -1) {
UniGraphVertexStep uniGraphVertexStep = new UniGraphVertexStep<>(vertexStep, uniGraph, uniGraph.getControllerManager());
TraversalHelper.replaceStep(vertexStep, uniGraphVertexStep, child1);
if (vertexStep.returnsEdge())
PredicatesUtil.collectPredicates(uniGraphVertexStep, child1);
}
});
traversalParent.getGlobalChildren().forEach(child1 -> {
if (TraversalHelper.stepIndex(vertexStep, child1) != -1) {
UniGraphVertexStep uniGraphVertexStep = new UniGraphVertexStep<>(vertexStep, uniGraph, uniGraph.getControllerManager());
TraversalHelper.replaceStep(vertexStep, uniGraphVertexStep, child1);
if (vertexStep.returnsEdge())
PredicatesUtil.collectPredicates(uniGraphVertexStep, child1);
}
});
});
}
});
});
}
});
}
Aggregations