Class TraversalHelper


  • public final class TraversalHelper
    extends Object
    Author:
    Marko A. Rodriguez (http://markorodriguez.com), Stephen Mallette (http://stephen.genoprime.com)
    • 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​(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)
      • getStepsOfAssignableClassRecursively

        public static List<Step<?,​?>> getStepsOfAssignableClassRecursively​(Traversal.Admin<?,​?> traversal,
                                                                                 Class<?>... stepClasses)
        Get steps of the specified classes throughout the traversal.
      • getStepsOfAssignableClassRecursivelyFromDepth

        public static List<Step<?,​?>> getStepsOfAssignableClassRecursivelyFromDepth​(Traversal.Admin<?,​?> traversal,
                                                                                          Class<?>... stepClasses)
        Get steps of the specified classes throughout the traversal, collecting them in a fashion that orders them from the deepest steps first.
      • 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
      • applyTraversalRecursively

        public static void applyTraversalRecursively​(Consumer<Traversal.Admin<?,​?>> consumer,
                                                     Traversal.Admin<?,​?> traversal,
                                                     boolean applyToChildrenOnly)
        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)
      • 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.
      • hasLabels

        public static boolean hasLabels​(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

        @Deprecated
        public static void applySingleLevelStrategies​(Traversal.Admin<?,​?> parentTraversal,
                                                      Traversal.Admin<?,​?> childTraversal,
                                                      Class<? extends TraversalStrategy> stopAfterStrategy)
        Deprecated.
        As of release 3.5.2, not replaced as strategies are not applied in this fashion after 3.5.0
      • 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