public static <T> Optional<T> firstElement(final Object obj, final Class<T> clazz) {
        var result = (Optional<T>) firstElement(obj);
        result.ifPresent(value -> Assert.isTrue(clazz.isAssignableFrom(value.getClass()), () -> "Invalid element subtype"));
        return result;
    }
Converts the provided object into a collection
and return the first element, or empty.

@param <T>   the type parameter
@param obj   the obj
@param clazz the clazz
@return the optional
core/cas-server-core-util-api/src/main/java/org/apereo/cas/util/CollectionUtils.java