public static <T> Set<T> toImmutableSet(Collection<? extends T> collection) {
        if (isImmutableSet(collection)) {
            return (Set<T>) collection;
        }
        if (collection.isEmpty()) {
            return Collections.emptySet();
        }
        return (Set<T>) Set.of(collection.toArray());
    }
Note that the method only checks the immutable classes used by Turms.
turms-server-common/src/main/java/im/turms/server/common/infra/collection/CollectionUtil.java