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

        prepare(traverser, traversal);

        final Step<?, E> endStep = traversal.getEndStep();
        boolean result = false;
        while (traversal.hasNext()) {
            if (endStep.next().get().equals(end)) {
                result = true;
                break;
            }
        }

        // The traversal might not have been fully consumed in the loop above. 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