TraversalHelper { public static <S, E> int stepIndex(final Step<S, E> step, final Traversal.Admin<?, ?> traversal) { int i = 0; for (final Step s : traversal.getSteps()) { if (s.equals(step, true)) return i; i++; } return -1; } private  TraversalHelper(); static boolean isLocalProperties(final Traversal.Admin<?, ?> traversal); static boolean isLocalStarGraph(final Traversal.Admin<?, ?> traversal); static void insertBeforeStep(final Step<S, E> insertStep, final Step<E, ?> afterStep, final Traversal.Admin<?, ?> traversal); static void insertAfterStep(final Step<S, E> insertStep, final Step<?, S> beforeStep, final Traversal.Admin<?, ?> traversal); static void replaceStep(final Step<S, E> removeStep, final Step<S, E> insertStep, final Traversal.Admin<?, ?> traversal); static Step<?, E> insertTraversal(final Step<?, S> previousStep, final Traversal.Admin<S, E> insertTraversal, final Traversal.Admin<?, ?> traversal); static Step<?, E> insertTraversal(final int insertIndex, final Traversal.Admin<S, E> insertTraversal, final Traversal.Admin<?, ?> traversal); static void removeToTraversal(final Step<S, ?> startStep, final Step<?, E> endStep, final Traversal.Admin<S, E> newTraversal); static int stepIndex(final Step<S, E> step, final Traversal.Admin<?, ?> traversal); static List<S> getStepsOfClass(final Class<S> stepClass, final Traversal.Admin<?, ?> traversal); static List<S> getStepsOfAssignableClass(final Class<S> stepClass, final Traversal.Admin<?, ?> traversal); static Optional<S> getLastStepOfAssignableClass(final Class<S> stepClass, final Traversal.Admin<?, ?> traversal); static Optional<S> getFirstStepOfAssignableClass(final Class<S> stepClass, final Traversal.Admin<?, ?> traversal); static List<S> getStepsOfAssignableClassRecursively(final Class<S> stepClass, final Traversal.Admin<?, ?> traversal); static List<S> getStepsOfAssignableClassRecursively(final Scope scope, final Class<S> stepClass, final Traversal.Admin<?, ?> traversal); static boolean isGlobalChild(Traversal.Admin<?, ?> traversal); static boolean hasStepOfClass(final Class stepClass, final Traversal.Admin<?, ?> traversal); static boolean hasStepOfAssignableClass(final Class superClass, final Traversal.Admin<?, ?> traversal); static boolean hasStepOfAssignableClassRecursively(final Class stepClass, final Traversal.Admin<?, ?> traversal); static boolean hasStepOfAssignableClassRecursively(final Scope scope, final Class stepClass, final Traversal.Admin<?, ?> traversal); static boolean hasStepOfAssignableClassRecursively(final Collection<Class> stepClasses, final Traversal.Admin<?, ?> traversal); static boolean hasStepOfAssignableClassRecursively(final Scope scope, final Collection<Class> stepClasses, final Traversal.Admin<?, ?> traversal); static boolean anyStepRecursively(final Predicate<Step> predicate, final Traversal.Admin<?, ?> traversal); static boolean anyStepRecursively(final Predicate<Step> predicate, final TraversalParent step); static void applyTraversalRecursively(final Consumer<Traversal.Admin<?, ?>> consumer, final Traversal.Admin<?, ?> traversal); static void addToCollection(final Collection<S> collection, final S s, final long bulk); static String getShortName(final Step step, final int maxLength); static void reIdSteps(final StepPosition stepPosition, final Traversal.Admin<?, ?> traversal); static Traversal.Admin<?, ?> getRootTraversal(Traversal.Admin<?, ?> traversal); static boolean hasLabels(final Traversal.Admin<?, ?> traversal); static Set<String> getLabels(final Traversal.Admin<?, ?> traversal); static Set<Scoping.Variable> getVariableLocations(final Traversal.Admin<?, ?> traversal); static boolean onGraphComputer(Traversal.Admin<?, ?> traversal); static void removeAllSteps(final Traversal.Admin<?, ?> traversal); static void copyLabels(final Step<?, ?> fromStep, final Step<?, ?> toStep, final boolean moveLabels); static boolean hasAllStepsOfClass(final Traversal.Admin<?, ?> traversal, final Class<?>... classesToCheck); static boolean hasStepOfClass(final Traversal.Admin<?, ?> traversal, final Class<?>... classesToCheck); static void applySingleLevelStrategies(final Traversal.Admin<?, ?> parentTraversal, final Traversal.Admin<?, ?> childTraversal, final Class<? extends TraversalStrategy> stopAfterStrategy); static T addHasContainer(final T traversal, final HasContainer hasContainer);  }
@Test public void shouldGetTheStepIndex() { final Traversal.Admin traversal = new DefaultTraversal<>(EmptyGraph.instance()); final HasStep hasStep = new HasStep(traversal); traversal.asAdmin().addStep(0, new HasStep(traversal)); traversal.asAdmin().addStep(0, hasStep); traversal.asAdmin().addStep(0, new HasStep(traversal)); assertEquals(1, TraversalHelper.stepIndex(hasStep, traversal)); }
@Test public void shouldNotFindTheStepIndex() { final Traversal.Admin traversal = new DefaultTraversal<>(EmptyGraph.instance()); final IdentityStep identityStep = new IdentityStep(traversal); traversal.asAdmin().addStep(0, new HasStep(traversal)); traversal.asAdmin().addStep(0, new HasStep(traversal)); traversal.asAdmin().addStep(0, new HasStep(traversal)); assertEquals(-1, TraversalHelper.stepIndex(identityStep, traversal)); }