Copy entire map of string collection. The copy is unmodifiable map of unmodifiable collections. @param map string collection map @return copy of the map or an empty map if the map is null.
(
Map<String, Collection<String>> map)
| 323 | * @return copy of the map or an empty map if the map is null. |
| 324 | */ |
| 325 | public static Map<String, Collection<String>> caseInsensitiveCopyOf( |
| 326 | Map<String, Collection<String>> map) { |
| 327 | if (map == null) { |
| 328 | return Collections.emptyMap(); |
| 329 | } |
| 330 | |
| 331 | Map<String, Collection<String>> result = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); |
| 332 | |
| 333 | for (Map.Entry<String, Collection<String>> entry : map.entrySet()) { |
| 334 | String key = entry.getKey(); |
| 335 | if (!result.containsKey(key)) { |
| 336 | result.put(key.toLowerCase(Locale.ROOT), new LinkedList<>()); |
| 337 | } |
| 338 | result.get(key).addAll(entry.getValue()); |
| 339 | } |
| 340 | result.replaceAll((key, value) -> Collections.unmodifiableCollection(value)); |
| 341 | |
| 342 | return Collections.unmodifiableMap(result); |
| 343 | } |
| 344 | |
| 345 | public static <T extends Enum<?>> T enumForName(Class<T> enumClass, Object object) { |
| 346 | String name = (nonNull(object)) ? object.toString() : null; |