@Override
    protected Vertex map(final Traverser.Admin<Edge> traverser) {
        final List<Object> objects = traverser.path().objects();
        for (int i = objects.size() - 2; i >= 0; i--) {
            if (objects.get(i) instanceof Vertex) {
                return ElementHelper.areEqual((Vertex) objects.get(i), traverser.get().outVertex()) ?
                        traverser.get().inVertex() :
                        traverser.get().outVertex();
            }
        }
        throw new IllegalStateException("The path history of the traverser does not contain a previous vertex: " + traverser.path());
    }
@author Marko A. Rodriguez (http://markorodriguez.com)
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/EdgeOtherVertexStep.java