public static <K, V> Map<V, Set<K>> reverseAsSetValues(
            Map<K, V> map,
            int expectedValuesPerKey) {
        Map<V, Set<K>> result = newMapWithExpectedSize(map.size());
        for (Map.Entry<K, V> keyAndValue : map.entrySet()) {
            result.computeIfAbsent(keyAndValue.getValue(),
                    key -> CollectionUtil.newSetWithExpectedSize(expectedValuesPerKey))
                    .add(keyAndValue.getKey());
        }
        return result;
    }
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