public static <S, E> Traversal.Admin<S, E> reverse(final Traversal.Admin<S, E> traversal) {
        for (final Step step : traversal.getSteps()) {
            if (step instanceof VertexStep)
                ((VertexStep) step).reverseDirection();
            if (step instanceof EdgeVertexStep)
                ((EdgeVertexStep) step).reverseDirection();
        }
        return traversal;
    }
@author Marko A. Rodriguez (http://markorodriguez.com)
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/VertexProgramHelper.java