/** * 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; }
/** * Determine if any step in {@link Traversal} or its children match the step given the provided {@link Predicate}. * * @param predicate the match function * @param traversal the traversal 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 Traversal.Admin<?, ?> traversal) { for (final Step<?, ?> step : traversal.getSteps()) { if (predicate.test(step)) { return true; } if (step instanceof TraversalParent && anyStepRecursively(predicate, ((TraversalParent) step))) { return true; } } return false; }
private static boolean usesLabels(final Step<?, ?> step, final Set<String> labels) { if (step instanceof LambdaHolder) return true; if (step instanceof Scoping) { final Set<String> scopes = ((Scoping) step).getScopeKeys(); for (final String label : labels) { if (scopes.contains(label)) return true; } } if (step instanceof TraversalParent) { if (TraversalHelper.anyStepRecursively(s -> usesLabels(s, labels), (TraversalParent) step)) return true; } return false; }
@Override public Set<String> getScopeKeys() { if (null == this.scopeKeys) { // computer the first time and then save resultant keys this.scopeKeys = new HashSet<>(); if (null != this.selectKey) this.scopeKeys.add(this.selectKey); final Set<String> endLabels = ((MatchStep<?, ?>) this.getTraversal().getParent()).getMatchEndLabels(); TraversalHelper.anyStepRecursively(step -> { if (step instanceof WherePredicateStep || step instanceof WhereTraversalStep) { for (final String key : ((Scoping) step).getScopeKeys()) { if (endLabels.contains(key)) this.scopeKeys.add(key); } } return false; }, this.getTraversal()); // this is the old way but it only checked for where() as the next step, not arbitrarily throughout traversal // just going to keep this in case something pops up in the future and this is needed as an original reference. /* if (this.getNextStep() instanceof WhereTraversalStep || this.getNextStep() instanceof WherePredicateStep) this.scopeKeys.addAll(((Scoping) this.getNextStep()).getScopeKeys());*/ this.scopeKeys = Collections.unmodifiableSet(this.scopeKeys); } return this.scopeKeys; } }
@Override public void apply(final Traversal.Admin<?, ?> traversal) { if (!(traversal.getParent() instanceof EmptyStep) || TraversalHelper.onGraphComputer(traversal)) return; final List<Step> steps = traversal.getSteps(); if (steps.size() < 2 || !(steps.get(0) instanceof GraphStep) || 0 != ((GraphStep) steps.get(0)).getIds().length || !(steps.get(steps.size() - 1) instanceof CountGlobalStep)) return; for (int i = 1; i < steps.size() - 1; i++) { final Step current = steps.get(i); if (!(//current instanceof MapStep || // MapSteps will not necessarily emit an element as demonstrated in https://issues.apache.org/jira/browse/TINKERPOP-1958 current instanceof IdentityStep || current instanceof NoOpBarrierStep || current instanceof CollectingBarrierStep) || (current instanceof TraversalParent && TraversalHelper.anyStepRecursively(s -> (s instanceof SideEffectStep || s instanceof AggregateStep), (TraversalParent) current))) return; } final Class<? extends Element> elementClass = ((GraphStep<?, ?>) steps.get(0)).getReturnClass(); TraversalHelper.removeAllSteps(traversal); traversal.addStep(new TinkerCountGlobalStep<>(traversal, elementClass)); }
TraversalHelper.anyStepRecursively(step -> step instanceof LambdaHolder || step.getRequirements().contains(TraverserRequirement.PATH) || (step instanceof VertexProgramStep &&
/** * 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; }
/** * Determine if any step in {@link Traversal} or its children match the step given the provided {@link Predicate}. * * @param predicate the match function * @param traversal the traversal 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 Traversal.Admin<?, ?> traversal) { for (final Step<?, ?> step : traversal.getSteps()) { if (predicate.test(step)) { return true; } if (step instanceof TraversalParent && anyStepRecursively(predicate, ((TraversalParent) step))) { return true; } } return false; }
private static boolean usesLabels(final Step<?, ?> step, final Set<String> labels) { if (step instanceof LambdaHolder) return true; if (step instanceof Scoping) { final Set<String> scopes = ((Scoping) step).getScopeKeys(); for (final String label : labels) { if (scopes.contains(label)) return true; } } if (step instanceof TraversalParent) { if (TraversalHelper.anyStepRecursively(s -> usesLabels(s, labels), (TraversalParent) step)) return true; } return false; }
@Override public Set<String> getScopeKeys() { if (null == this.scopeKeys) { // computer the first time and then save resultant keys this.scopeKeys = new HashSet<>(); if (null != this.selectKey) this.scopeKeys.add(this.selectKey); final Set<String> endLabels = ((MatchStep<?, ?>) this.getTraversal().getParent()).getMatchEndLabels(); TraversalHelper.anyStepRecursively(step -> { if (step instanceof WherePredicateStep || step instanceof WhereTraversalStep) { for (final String key : ((Scoping) step).getScopeKeys()) { if (endLabels.contains(key)) this.scopeKeys.add(key); } } return false; }, this.getTraversal()); // this is the old way but it only checked for where() as the next step, not arbitrarily throughout traversal // just going to keep this in case something pops up in the future and this is needed as an original reference. /* if (this.getNextStep() instanceof WhereTraversalStep || this.getNextStep() instanceof WherePredicateStep) this.scopeKeys.addAll(((Scoping) this.getNextStep()).getScopeKeys());*/ this.scopeKeys = Collections.unmodifiableSet(this.scopeKeys); } return this.scopeKeys; } }
@Override public void apply(final Traversal.Admin<?, ?> traversal) { if (!(traversal.getParent() instanceof EmptyStep) || TraversalHelper.onGraphComputer(traversal)) return; final List<Step> steps = traversal.getSteps(); if (steps.size() < 2 || !(steps.get(0) instanceof GraphStep) || 0 != ((GraphStep) steps.get(0)).getIds().length || !(steps.get(steps.size() - 1) instanceof CountGlobalStep)) return; for (int i = 1; i < steps.size() - 1; i++) { final Step current = steps.get(i); if (!(//current instanceof MapStep || // MapSteps will not necessarily emit an element as demonstrated in https://issues.apache.org/jira/browse/TINKERPOP-1958 current instanceof IdentityStep || current instanceof NoOpBarrierStep || current instanceof CollectingBarrierStep) || (current instanceof TraversalParent && TraversalHelper.anyStepRecursively(s -> (s instanceof SideEffectStep || s instanceof AggregateStep), (TraversalParent) current))) return; } final Class<? extends Element> elementClass = ((GraphStep<?, ?>) steps.get(0)).getReturnClass(); TraversalHelper.removeAllSteps(traversal); traversal.addStep(new TinkerCountGlobalStep<>(traversal, elementClass)); }
@Override public void apply(final Traversal.Admin<?, ?> traversal) { if (!(traversal.getParent() instanceof EmptyStep) || TraversalHelper.onGraphComputer(traversal)) return; final List<Step> steps = traversal.getSteps(); if (steps.size() < 2 || !(steps.get(0) instanceof GraphStep) || 0 != ((GraphStep) steps.get(0)).getIds().length || !(steps.get(steps.size() - 1) instanceof CountGlobalStep)) return; for (int i = 1; i < steps.size() - 1; i++) { final Step current = steps.get(i); if (!(//current instanceof MapStep || // MapSteps will not necessarily emit an element as demonstrated in https://issues.apache.org/jira/browse/TINKERPOP-1958 current instanceof IdentityStep || current instanceof NoOpBarrierStep || current instanceof CollectingBarrierStep) || (current instanceof TraversalParent && TraversalHelper.anyStepRecursively(s -> (s instanceof SideEffectStep || s instanceof AggregateStep), (TraversalParent) current))) return; } final Class<? extends Element> elementClass = ((GraphStep<?, ?>) steps.get(0)).getReturnClass(); TraversalHelper.removeAllSteps(traversal); traversal.addStep(new TinkerCountGlobalStep<>(traversal, elementClass)); }
TraversalHelper.anyStepRecursively(step -> step instanceof LambdaHolder || step.getRequirements().contains(TraverserRequirement.PATH) || (step instanceof VertexProgramStep &&