Created
May 14, 2014 18:08
-
-
Save spmallette/71adfe53c367464ce9a4 to your computer and use it in GitHub Desktop.
PartitionGraphStrategyOptimizer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void optimize(final Traversal traversal) { | |
// inject a HasStep after each GraphStep, VertexStep or EdgeVertexStep | |
final List<Class> stepsToLookFor = Arrays.<Class>asList(GraphStep.class, VertexStep.class, EdgeVertexStep.class); | |
final List<Integer> positions = new ArrayList<>(); | |
final List<?> traversalSteps = traversal.getSteps(); | |
for (int ix = 0; ix < traversalSteps.size(); ix++) { | |
final int pos = ix; | |
if (stepsToLookFor.stream().anyMatch(c -> c.isAssignableFrom(traversalSteps.get(pos).getClass()))) positions.add(ix); | |
} | |
Collections.reverse(positions); | |
for (int pos : positions) { | |
final MapStep transformToStrategy = new MapStep(traversal); | |
transformToStrategy.setFunction((t) -> { | |
if (t instanceof Vertex) | |
return new StrategyWrappedVertex((Vertex) t, graph); | |
else if (t instanceof Edge) | |
return new StrategyWrappedEdge((Edge) t, graph); | |
else | |
return t; | |
}); | |
//TraversalHelper.insertStep(transformToStrategy, pos + 1, traversal); | |
TraversalHelper.insertStep(new HasStep(traversal, new HasContainer(this.partitionKey, T.convert(T.in), readPartitions)), pos + 1, traversal); | |
System.out.println(traversal); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment