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;
    }
Gets the index of a particular step in the {@link Traversal}.

@param step      the step to retrieve the index for
@param traversal the traversal to perform the action on
@return the index of the step or -1 if the step is not present
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalHelper.java