@Override
        public boolean test(final Object first, final Collection second) {
            if (first instanceof Element &&
                    second instanceof BulkSet<?> &&
                    first.getClass() == ((BulkSet<?>)second).getAllContainedElementsClass()) {
                /*
                 * For elements (i.e., vertices, edges, vertex properties) it is safe to use the contains check
                 * since the hash code computation and equals comparison give the same result as the Gremlin equality comparison
                 * (using GremlinValueComparator.COMPARABILITY.equals) based on the Gremlin comparison semantics
                 * (cf. <a href="https://tinkerpop.apache.org/docs/3.7.0/dev/provider/#gremlin-semantics-concepts">...</a>).
                 * In both cases, we just compare the ids of the elements. Therefore, it is safe to use the contains check.
                 */
                return second.contains(first);
            }
            GremlinTypeErrorException typeError = null;
            for (final Object o : second) {
                try {
                    if (Compare.eq.test(first, o))
                        return true;
                } catch (GremlinTypeErrorException ex) {
                    // hold onto it until the end in case any other arguments evaluate to TRUE
                    typeError = ex;
                }
            }
            if (typeError != null)
                throw typeError;
            return false;
        }
The first object is within the {@code Collection} provided in the second object. The second object may not be
{@code null}.

@since 3.0.0-incubating
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Contains.java