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 Description static <T extends Traversal.Admin<?,?>>
TaddHasContainer(T traversal, HasContainer hasContainer)
Used to left-fold aHasContainer
to aHasContainerHolder
if it exists.static <S> void
addToCollection(Collection<S> collection, S s, long bulk)
static boolean
anyStepRecursively(Predicate<Step> predicate, TraversalParent step)
Determine if any child step of aTraversalParent
match the step given the providedPredicate
.static boolean
anyStepRecursively(Predicate<Step> predicate, Traversal.Admin<?,?> traversal)
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.0static void
applyTraversalRecursively(Consumer<Traversal.Admin<?,?>> consumer, Traversal.Admin<?,?> traversal)
static void
applyTraversalRecursively(Consumer<Traversal.Admin<?,?>> consumer, Traversal.Admin<?,?> traversal, boolean applyToChildrenOnly)
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 List<Step<?,?>>
getStepsOfAssignableClassRecursively(Traversal.Admin<?,?> traversal, Class<?>... stepClasses)
Get steps of the specified classes throughout the traversal.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.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 currentTraversal
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 currentTraversal
and its global or local child traversals.static boolean
hasStepOfAssignableClassRecursively(Scope scope, Class stepClass, Traversal.Admin<?,?> traversal)
static boolean
hasStepOfAssignableClassRecursively(Scope scope, Collection<Class> stepClasses, Traversal.Admin<?,?> traversal)
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>
voidinsertAfterStep(Step<S,E> insertStep, Step<?,S> beforeStep, Traversal.Admin<?,?> traversal)
Insert a step after a specified step instance.static <S,E>
voidinsertBeforeStep(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>
voidremoveToTraversal(Step<S,?> startStep, Step<?,E> endStep, Traversal.Admin<S,E> newTraversal)
static <S,E>
voidreplaceStep(Step<S,E> removeStep, Step<S,E> insertStep, Traversal.Admin<?,?> traversal)
Replace a step with a new step.static <S,E>
intstepIndex(Step<S,E> step, Traversal.Admin<?,?> traversal)
Gets the index of a particular step in theTraversal
.
-
-
-
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 insertafterStep
- the step to insert the new step beforetraversal
- 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 insertbeforeStep
- the step to insert the new step aftertraversal
- 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 removeinsertStep
- the step to inserttraversal
- 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 theTraversal
.- Parameters:
step
- the step to retrieve the index fortraversal
- 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 fortraversal
- the traversal to perform the action on- Returns:
true
if the class is found andfalse
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 fortraversal
- the traversal to perform the action on- Returns:
true
if the class is found andfalse
otherwise
-
hasStepOfAssignableClassRecursively
public static boolean hasStepOfAssignableClassRecursively(Class stepClass, Traversal.Admin<?,?> traversal)
Determine if the traversal has a step of an assignable class in the currentTraversal
and its local and global child traversals.- Parameters:
stepClass
- the step class to look fortraversal
- 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 givenstepClass
, otherwisefalse
.
-
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 currentTraversal
and itsScope
child traversals.- Parameters:
scope
- the child traversal scope to checkstepClass
- the step class to look fortraversal
- 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 givenstepClass
, otherwisefalse
.
-
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 currentTraversal
and its global or local child traversals.- Parameters:
stepClasses
- the step classes to look fortraversal
- 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 instepClasses
, otherwisefalse
.
-
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 currentTraversal
and itsScope
child traversals.- Parameters:
scope
- whether to check global or local children (null for both).stepClasses
- the step classes to look fortraversal
- 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 instepClasses
, otherwisefalse
.
-
anyStepRecursively
public static boolean anyStepRecursively(Predicate<Step> predicate, Traversal.Admin<?,?> traversal)
- Parameters:
predicate
- the match functiontraversal
- the traversal to perform the action on- Returns:
true
if there is a match andfalse
otherwise
-
anyStepRecursively
public static boolean anyStepRecursively(Predicate<Step> predicate, TraversalParent step)
Determine if any child step of aTraversalParent
match the step given the providedPredicate
.- Parameters:
predicate
- the match functionstep
- the step to perform the action on- Returns:
true
if there is a match andfalse
otherwise
-
applyTraversalRecursively
public static void applyTraversalRecursively(Consumer<Traversal.Admin<?,?>> consumer, Traversal.Admin<?,?> traversal)
- Parameters:
consumer
- the function to apply to the each traversal in the treetraversal
- the root traversal to start application
-
applyTraversalRecursively
public static void applyTraversalRecursively(Consumer<Traversal.Admin<?,?>> consumer, Traversal.Admin<?,?> traversal, boolean applyToChildrenOnly)
- Parameters:
consumer
- the function to apply to the each traversal in the treetraversal
- 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.
-
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
@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)
- 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
-
-