public static Map<String, Collection<String>> caseInsensitiveCopyOf(Map<String, Collection<String>> map) {
    if (map == null) {
      return Collections.emptyMap();
    }

    Map<String, Collection<String>> result =
        new TreeMap<>(String.CASE_INSENSITIVE_ORDER);

    for (Map.Entry<String, Collection<String>> entry : map.entrySet()) {
      String key = entry.getKey();
      if (!result.containsKey(key)) {
        result.put(key.toLowerCase(Locale.ROOT), new LinkedList<>());
      }
      result.get(key).addAll(entry.getValue());
    }
    result.replaceAll((key, value) -> Collections.unmodifiableCollection(value));

    return Collections.unmodifiableMap(result);
  }
@Test
  void copyIsUnmodifiable() {
    // Arrange
    Map<String, Collection<String>> sourceMap = new HashMap<>();

    sourceMap.put("First", Arrays.asList("abc", "qwerty", "xyz"));
    sourceMap.put("camelCase", Collections.singleton("123"));
    // Act
    Map<String, Collection<String>> unmodifiableMap = caseInsensitiveCopyOf(sourceMap);
    // Assert result
    assertThatThrownBy(() -> unmodifiableMap.put("new", Collections.singleton("223322")))
        .isInstanceOf(UnsupportedOperationException.class);
    assertThatThrownBy(() -> unmodifiableMap.get("camelCase").clear())
        .isInstanceOf(UnsupportedOperationException.class);
  }