@SuppressWarnings("JdkObsolete")
    public static Set<Object> toCollection(final Object obj) {
        val resultingSet = new LinkedHashSet<>();
        if (obj == null) {
            LOGGER.trace("Converting null obj to empty collection");
        } else if (obj instanceof final Collection values) {
            resultingSet.addAll(values);
            LOGGER.trace("Converting multi-valued element [{}]", obj);
        } else if (obj instanceof final Map map) {
            val set = (Set<Map.Entry>) map.entrySet();
            resultingSet.addAll(set.stream().map(e -> Pair.of(e.getKey(), e.getValue())).collect(Collectors.toSet()));
        } else if (obj.getClass().isArray()) {
            if (obj instanceof byte[]) {
                resultingSet.add(obj);
            } else {
                resultingSet.addAll(Arrays.stream((Object[]) obj).collect(Collectors.toSet()));
            }
            LOGGER.trace("Converting array element [{}]", obj);
        } else if (obj instanceof final Iterator it) {
            while (it.hasNext()) {
                resultingSet.add(it.next());
            }
        } else if (obj instanceof final Enumeration it) {
            while (it.hasMoreElements()) {
                resultingSet.add(it.nextElement());
            }
        } else {
            resultingSet.add(obj);
            LOGGER.trace("Converting element [{}]", obj);
        }
        return resultingSet.stream().filter(Objects::nonNull).collect(Collectors.toCollection(LinkedHashSet::new));
    }
Convert the object given into a {@link Collection} instead.

@param obj the object to convert into a collection
@return The collection instance containing the object provided
core/cas-server-core-util-api/src/main/java/org/apereo/cas/util/CollectionUtils.java