Java Code Examples for org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent#getLocalChildren()

The following examples show how to use org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent#getLocalChildren() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ByModulatorOptimizationStrategy.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
    final Step step = traversal.getParent().asStep();
    if (step instanceof ByModulating && step instanceof TraversalParent) {
        final TraversalParent byModulatingStep = (TraversalParent) step;
        if (step instanceof Grouping) {
            final Grouping grouping = (Grouping) step;
            optimizeByModulatingTraversal(byModulatingStep, grouping.getKeyTraversal());

            // the value by() needs different handling because by(Traversal) only equals by(String) or by(T)
            // if the traversal does a fold().
            final Traversal.Admin<?, ?> currentValueTraversal = grouping.getValueTraversal();
            final List<Step> stepsInCurrentValueTraversal = currentValueTraversal.getSteps();
            if (stepsInCurrentValueTraversal.size() == 1 && stepsInCurrentValueTraversal.get(0) instanceof IdentityStep)
                optimizeForStep(byModulatingStep, currentValueTraversal, stepsInCurrentValueTraversal.get(0));
            else if (stepsInCurrentValueTraversal.size() == 2 && stepsInCurrentValueTraversal.get(1) instanceof FoldStep)
                optimizeForStep(byModulatingStep, currentValueTraversal, stepsInCurrentValueTraversal.get(0));

        } else {
            for (final Traversal.Admin<?, ?> byModulatingTraversal : byModulatingStep.getLocalChildren()) {
                optimizeByModulatingTraversal(byModulatingStep, byModulatingTraversal);
            }
        }
    }
}
 
Example 2
Source File: TraversalHelper.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
/**
 * Determine if any child step of a {@link TraversalParent} match the step given the provided {@link Predicate}.
 *
 * @param predicate the match function
 * @param step      the step to perform the action on
 * @return {@code true} if there is a match and {@code false} otherwise
 */
public static boolean anyStepRecursively(final Predicate<Step> predicate, final TraversalParent step) {
    for (final Traversal.Admin<?, ?> localChild : step.getLocalChildren()) {
        if (anyStepRecursively(predicate, localChild)) return true;
    }
    for (final Traversal.Admin<?, ?> globalChild : step.getGlobalChildren()) {
        if (anyStepRecursively(predicate, globalChild)) return true;
    }
    return false;
}
 
Example 3
Source File: FilterRankingStrategy.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
private static int getMaxStepRank(final TraversalParent parent, final int startRank) {
    int maxStepRank = startRank;
    // no filter steps are global parents (yet)
    for (final Traversal.Admin<?, ?> traversal : parent.getLocalChildren()) {
        for (final Step<?, ?> step : traversal.getSteps()) {
            final int stepRank = getStepRank(step);
            if (stepRank > maxStepRank)
                maxStepRank = stepRank;
        }
    }
    return maxStepRank;
}
 
Example 4
Source File: SqlgTraversalUtil.java    From sqlg with MIT License 5 votes vote down vote up
private static boolean anyStepRecursively(final Predicate<Step> predicate, final TraversalParent step) {
    for (final Traversal.Admin<?, ?> localChild : step.getLocalChildren()) {
        if (anyStepRecursively(predicate, localChild)) return true;
    }
    for (final Traversal.Admin<?, ?> globalChild : step.getGlobalChildren()) {
        if (anyStepRecursively(predicate, globalChild)) return true;
    }
    return false;
}