org.apache.tinkerpop.gremlin.process.traversal.util

## Class TraversalHelper

- java.lang.Object
- - org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper

-     public final class TraversalHelper
      extends Object

  Author:
    Marko A. Rodriguez (http://markorodriguez.com), Stephen Mallette (http://stephen.genoprime.com)

- - ### Method Summary

    All Methods Static Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `static <T extends Traversal.Admin<?,?>> T` | `addHasContainer(T traversal, HasContainer hasContainer)` Used to left-fold a `HasContainer` to a `HasContainerHolder` if it exists.
    `static <S> void` | `addToCollection(Collection<S> collection, S s, long bulk)`
    `static <S> void` | `addToCollectionUnrollIterator(Collection<S> collection, S s, long bulk)` Deprecated. As of release 3.2.3, not replaced - only used by `GroupStepV3d0`.
    `static boolean` | `anyStepRecursively(Predicate<Step> predicate, Traversal.Admin<?,?> traversal)` Determine if any step in `Traversal` or its children match the step given the provided `Predicate`.
    `static boolean` | `anyStepRecursively(Predicate<Step> predicate, TraversalParent step)` Determine if any child step of a `TraversalParent` match the step given the provided `Predicate`.
    `static void` | `applySingleLevelStrategies(Traversal.Admin<?,?> parentTraversal, Traversal.Admin<?,?> childTraversal, Class<? extends TraversalStrategy> stopAfterStrategy)`
    `static void` | `applyTraversalRecursively(Consumer<Traversal.Admin<?,?>> consumer, Traversal.Admin<?,?> traversal)` Apply the provider `Consumer` function to the provided `Traversal` and all of its children.
    `static void` | `copyLabels(Step<?,?> fromStep, Step<?,?> toStep, boolean moveLabels)`
    `static <S> Optional<S>` | `getFirstStepOfAssignableClass(Class<S> stepClass, Traversal.Admin<?,?> traversal)`
    `static Set<String>` | `getLabels(Traversal.Admin<?,?> traversal)`
    `static <S> Optional<S>` | `getLastStepOfAssignableClass(Class<S> stepClass, Traversal.Admin<?,?> traversal)`
    `static Traversal.Admin<?,?>` | `getRootTraversal(Traversal.Admin<?,?> traversal)`
    `static String` | `getShortName(Step step, int maxLength)` Returns the name of step truncated to maxLength.
    `static <S> List<S>` | `getStepsOfAssignableClass(Class<S> stepClass, Traversal.Admin<?,?> traversal)`
    `static <S> List<S>` | `getStepsOfAssignableClassRecursively(Class<S> stepClass, Traversal.Admin<?,?> traversal)`
    `static <S> List<S>` | `getStepsOfAssignableClassRecursively(Scope scope, Class<S> stepClass, Traversal.Admin<?,?> traversal)`
    `static <S> List<S>` | `getStepsOfClass(Class<S> stepClass, Traversal.Admin<?,?> traversal)`
    `static Set<Scoping.Variable>` | `getVariableLocations(Traversal.Admin<?,?> traversal)`
    `static boolean` | `hasAllStepsOfClass(Traversal.Admin<?,?> traversal, Class<?>... classesToCheck)`
    `static boolean` | `hasLabels(Traversal.Admin<?,?> traversal)`
    `static boolean` | `hasStepOfAssignableClass(Class superClass, Traversal.Admin<?,?> traversal)` Determine if the traversal has a step of an assignable class.
    `static boolean` | `hasStepOfAssignableClassRecursively(Class stepClass, Traversal.Admin<?,?> traversal)` Determine if the traversal has a step of an assignable class in the current `Traversal` and its local and global child traversals.
    `static boolean` | `hasStepOfAssignableClassRecursively(Collection<Class> stepClasses, Traversal.Admin<?,?> traversal)` Determine if the traversal has any of the supplied steps of an assignable class in the current `Traversal` and its global or local child traversals.
    `static boolean` | `hasStepOfAssignableClassRecursively(Scope scope, Class stepClass, Traversal.Admin<?,?> traversal)` Determine if the traversal has a step of an assignable class in the current `Traversal` and its `Scope` child traversals.
    `static boolean` | `hasStepOfAssignableClassRecursively(Scope scope, Collection<Class> stepClasses, Traversal.Admin<?,?> traversal)` Determine if the traversal has any of the supplied steps of an assignable class in the current `Traversal` and its `Scope` child traversals.
    `static boolean` | `hasStepOfClass(Class stepClass, Traversal.Admin<?,?> traversal)` Determine if the traversal has a step of a particular class.
    `static boolean` | `hasStepOfClass(Traversal.Admin<?,?> traversal, Class<?>... classesToCheck)`
    `static <S,E> void` | `insertAfterStep(Step<S,E> insertStep, Step<?,S> beforeStep, Traversal.Admin<?,?> traversal)` Insert a step after a specified step instance.
    `static <S,E> void` | `insertBeforeStep(Step<S,E> insertStep, Step<E,?> afterStep, Traversal.Admin<?,?> traversal)` Insert a step before a specified step instance.
    `static <S,E> Step<?,E>` | `insertTraversal(int insertIndex, Traversal.Admin<S,E> insertTraversal, Traversal.Admin<?,?> traversal)`
    `static <S,E> Step<?,E>` | `insertTraversal(Step<?,S> previousStep, Traversal.Admin<S,E> insertTraversal, Traversal.Admin<?,?> traversal)`
    `static boolean` | `isGlobalChild(Traversal.Admin<?,?> traversal)`
    `static boolean` | `isLocalProperties(Traversal.Admin<?,?> traversal)`
    `static boolean` | `isLocalStarGraph(Traversal.Admin<?,?> traversal)`
    `static boolean` | `onGraphComputer(Traversal.Admin<?,?> traversal)`
    `static void` | `reIdSteps(StepPosition stepPosition, Traversal.Admin<?,?> traversal)`
    `static void` | `removeAllSteps(Traversal.Admin<?,?> traversal)`
    `static <S,E> void` | `removeToTraversal(Step<S,?> startStep, Step<?,E> endStep, Traversal.Admin<S,E> newTraversal)`
    `static <S,E> void` | `replaceStep(Step<S,E> removeStep, Step<S,E> insertStep, Traversal.Admin<?,?> traversal)` Replace a step with a new step.
    `static <S,E> int` | `stepIndex(Step<S,E> step, Traversal.Admin<?,?> traversal)` Gets the index of a particular step in the `Traversal`.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### isLocalProperties

          public static boolean isLocalProperties(Traversal.Admin<?,?> traversal)

    - #### isLocalStarGraph

          public static boolean isLocalStarGraph(Traversal.Admin<?,?> traversal)

    - #### insertBeforeStep

          public static <S,E> void insertBeforeStep(Step<S,E> insertStep,
                                                    Step<E,?> afterStep,
                                                    Traversal.Admin<?,?> traversal)

      Insert a step before a specified step instance.
      Parameters:
        `insertStep` - the step to insert
        `afterStep` - the step to insert the new step before
        `traversal` - the traversal on which the action should occur

    - #### insertAfterStep

          public static <S,E> void insertAfterStep(Step<S,E> insertStep,
                                                   Step<?,S> beforeStep,
                                                   Traversal.Admin<?,?> traversal)

      Insert a step after a specified step instance.
      Parameters:
        `insertStep` - the step to insert
        `beforeStep` - the step to insert the new step after
        `traversal` - the traversal on which the action should occur

    - #### replaceStep

          public static <S,E> void replaceStep(Step<S,E> removeStep,
                                               Step<S,E> insertStep,
                                               Traversal.Admin<?,?> traversal)

      Replace a step with a new step.
      Parameters:
        `removeStep` - the step to remove
        `insertStep` - the step to insert
        `traversal` - the traversal on which the action will occur

    - #### insertTraversal

          public static <S,E> Step<?,E> insertTraversal(Step<?,S> previousStep,
                                                        Traversal.Admin<S,E> insertTraversal,
                                                        Traversal.Admin<?,?> traversal)

    - #### insertTraversal

          public static <S,E> Step<?,E> insertTraversal(int insertIndex,
                                                        Traversal.Admin<S,E> insertTraversal,
                                                        Traversal.Admin<?,?> traversal)

    - #### removeToTraversal

          public static <S,E> void removeToTraversal(Step<S,?> startStep,
                                                     Step<?,E> endStep,
                                                     Traversal.Admin<S,E> newTraversal)

    - #### stepIndex

          public static <S,E> int stepIndex(Step<S,E> step,
                                            Traversal.Admin<?,?> traversal)

      Gets the index of a particular step in the `Traversal`.
      Parameters:
        `step` - the step to retrieve the index for
        `traversal` - the traversal to perform the action on
      Returns:
        the index of the step or -1 if the step is not present

    - #### getStepsOfClass

          public static <S> List<S> getStepsOfClass(Class<S> stepClass,
                                                    Traversal.Admin<?,?> traversal)

    - #### getStepsOfAssignableClass

          public static <S> List<S> getStepsOfAssignableClass(Class<S> stepClass,
                                                              Traversal.Admin<?,?> traversal)

    - #### getLastStepOfAssignableClass

          public static <S> Optional<S> getLastStepOfAssignableClass(Class<S> stepClass,
                                                                     Traversal.Admin<?,?> traversal)

    - #### getFirstStepOfAssignableClass

          public static <S> Optional<S> getFirstStepOfAssignableClass(Class<S> stepClass,
                                                                      Traversal.Admin<?,?> traversal)

    - #### getStepsOfAssignableClassRecursively

          public static <S> List<S> getStepsOfAssignableClassRecursively(Class<S> stepClass,
                                                                         Traversal.Admin<?,?> traversal)

    - #### getStepsOfAssignableClassRecursively

          public static <S> List<S> getStepsOfAssignableClassRecursively(Scope scope,
                                                                         Class<S> stepClass,
                                                                         Traversal.Admin<?,?> traversal)

    - #### isGlobalChild

          public static boolean isGlobalChild(Traversal.Admin<?,?> traversal)

    - #### hasStepOfClass

          public static boolean hasStepOfClass(Class stepClass,
                                               Traversal.Admin<?,?> traversal)

      Determine if the traversal has a step of a particular class.
      Parameters:
        `stepClass` - the step class to look for
        `traversal` - the traversal to perform the action on
      Returns:
        `true` if the class is found and `false` otherwise

    - #### hasStepOfAssignableClass

          public static boolean hasStepOfAssignableClass(Class superClass,
                                                         Traversal.Admin<?,?> traversal)

      Determine if the traversal has a step of an assignable class.
      Parameters:
        `superClass` - the step super class to look for
        `traversal` - the traversal to perform the action on
      Returns:
        `true` if the class is found and `false` otherwise

    - #### hasStepOfAssignableClassRecursively

          public static boolean hasStepOfAssignableClassRecursively(Class stepClass,
                                                                    Traversal.Admin<?,?> traversal)

      Determine if the traversal has a step of an assignable class in the current `Traversal` and its local and global child traversals.
      Parameters:
        `stepClass` - the step class to look for
        `traversal` - the traversal in which to look for the given step class
      Returns:
        `true` if any step in the given traversal (and its child traversals) is an instance of the given `stepClass`, otherwise `false`.

    - #### hasStepOfAssignableClassRecursively

          public static boolean hasStepOfAssignableClassRecursively(Scope scope,
                                                                    Class stepClass,
                                                                    Traversal.Admin<?,?> traversal)

      Determine if the traversal has a step of an assignable class in the current `Traversal` and its `Scope` child traversals.
      Parameters:
        `scope` - the child traversal scope to check
        `stepClass` - the step class to look for
        `traversal` - the traversal in which to look for the given step class
      Returns:
        `true` if any step in the given traversal (and its child traversals) is an instance of the given `stepClass`, otherwise `false`.

    - #### hasStepOfAssignableClassRecursively

          public static boolean hasStepOfAssignableClassRecursively(Collection<Class> stepClasses,
                                                                    Traversal.Admin<?,?> traversal)

      Determine if the traversal has any of the supplied steps of an assignable class in the current `Traversal` and its global or local child traversals.
      Parameters:
        `stepClasses` - the step classes to look for
        `traversal` - the traversal in which to look for the given step classes
      Returns:
        `true` if any step in the given traversal (and its child traversals) is an instance of a class provided in `stepClasses`, otherwise `false`.

    - #### hasStepOfAssignableClassRecursively

          public static boolean hasStepOfAssignableClassRecursively(Scope scope,
                                                                    Collection<Class> stepClasses,
                                                                    Traversal.Admin<?,?> traversal)

      Determine if the traversal has any of the supplied steps of an assignable class in the current `Traversal` and its `Scope` child traversals.
      Parameters:
        `scope` - whether to check global or local children (null for both).
        `stepClasses` - the step classes to look for
        `traversal` - the traversal in which to look for the given step classes
      Returns:
        `true` if any step in the given traversal (and its child traversals) is an instance of a class provided in `stepClasses`, otherwise `false`.

    - #### anyStepRecursively

          public static boolean anyStepRecursively(Predicate<Step> predicate,
                                                   Traversal.Admin<?,?> traversal)

      Determine if any step in `Traversal` or its children match the step given the provided `Predicate`.
      Parameters:
        `predicate` - the match function
        `traversal` - the traversal to perform the action on
      Returns:
        `true` if there is a match and `false` otherwise

    - #### anyStepRecursively

          public static boolean anyStepRecursively(Predicate<Step> predicate,
                                                   TraversalParent step)

      Determine if any child step of a `TraversalParent` match the step given the provided `Predicate`.
      Parameters:
        `predicate` - the match function
        `step` - the step to perform the action on
      Returns:
        `true` if there is a match and `false` otherwise

    - #### applyTraversalRecursively

          public static void applyTraversalRecursively(Consumer<Traversal.Admin<?,?>> consumer,
                                                       Traversal.Admin<?,?> traversal)

      Apply the provider `Consumer` function to the provided `Traversal` and all of its children.
      Parameters:
        `consumer` - the function to apply to the each traversal in the tree
        `traversal` - the root traversal to start application

    - #### addToCollection

          public static <S> void addToCollection(Collection<S> collection,
                                                 S s,
                                                 long bulk)

    - #### addToCollectionUnrollIterator

          @Deprecated
          public static <S> void addToCollectionUnrollIterator(Collection<S> collection,
                                                                           S s,
                                                                           long bulk)

      Deprecated. As of release 3.2.3, not replaced - only used by `GroupStepV3d0`.

    - #### getShortName

          public static String getShortName(Step step,
                                            int maxLength)

      Returns the name of step truncated to maxLength. An ellipses is appended when the name exceeds maxLength.
      Parameters:
        `step` -
        `maxLength` - Includes the 3 "..." characters that will be appended when the length of the name exceeds maxLength.
      Returns:
        short step name.

    - #### reIdSteps

          public static void reIdSteps(StepPosition stepPosition,
                                       Traversal.Admin<?,?> traversal)

    - #### getRootTraversal

          public static Traversal.Admin<?,?> getRootTraversal(Traversal.Admin<?,?> traversal)

    - #### hasLabels

          public static boolean hasLabels(Traversal.Admin<?,?> traversal)

    - #### getLabels

          public static Set<String> getLabels(Traversal.Admin<?,?> traversal)

    - #### getVariableLocations

          public static Set<Scoping.Variable> getVariableLocations(Traversal.Admin<?,?> traversal)

    - #### onGraphComputer

          public static boolean onGraphComputer(Traversal.Admin<?,?> traversal)

    - #### removeAllSteps

          public static void removeAllSteps(Traversal.Admin<?,?> traversal)

    - #### copyLabels

          public static void copyLabels(Step<?,?> fromStep,
                                        Step<?,?> toStep,
                                        boolean moveLabels)

    - #### hasAllStepsOfClass

          public static boolean hasAllStepsOfClass(Traversal.Admin<?,?> traversal,
                                                   Class<?>... classesToCheck)

    - #### hasStepOfClass

          public static boolean hasStepOfClass(Traversal.Admin<?,?> traversal,
                                               Class<?>... classesToCheck)

    - #### applySingleLevelStrategies

          public static void applySingleLevelStrategies(Traversal.Admin<?,?> parentTraversal,
                                                        Traversal.Admin<?,?> childTraversal,
                                                        Class<? extends TraversalStrategy> stopAfterStrategy)

    - #### addHasContainer

          public static <T extends Traversal.Admin<?,?>> T addHasContainer(T traversal,
                                                                           HasContainer hasContainer)

      Used to left-fold a `HasContainer` to a `HasContainerHolder` if it exists. Else, append a `HasStep`.
      Type Parameters:
        `T` - the traversal type
      Parameters:
        `traversal` - the traversal to fold or append.
        `hasContainer` - the container to add left or append.
      Returns:
        the has container folded or appended traversal

Copyright © 2013–2019 Apache Software Foundation. All rights reserved.