public static <S, E> boolean test(final S start, final Traversal.Admin<S, E> traversal, final E end) {
        if (null == end) return TraversalUtil.test(start, traversal);

        traversal.reset();
        traversal.addStart(traversal.getTraverserGenerator().generate(start, traversal.getStartStep(), 1l));
        final Step<?, E> endStep = traversal.getEndStep();

        boolean result = false;
        while (traversal.hasNext()) {
            if (endStep.next().get().equals(end)) {
                result = true;
                break;
            }
        }

        //Close the traversal to release any underlying resources.
        CloseableIterator.closeIterator(traversal);

        return result;
    }
@author Marko A. Rodriguez (http://markorodriguez.com)
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalUtil.java