Skip to content

Commit

Permalink
Create immutable MultiValueMap wrapper
Browse files Browse the repository at this point in the history
This commit introduces UnmodifiableMultiValueMap, an immutable wrapper
around a MultiValueMap, similar to what is returned by
Collections.unmodifiable*.
CollectionUtils::unmodifiableMultiValueMap now returns
UnmodifiableMultiValueMap.

Closes spring-projectsgh-27608
  • Loading branch information
poutsma committed Oct 25, 2021
1 parent 683bdf2 commit af4e677
Show file tree
Hide file tree
Showing 4 changed files with 910 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -470,13 +470,10 @@ public static <K, V> MultiValueMap<K, V> unmodifiableMultiValueMap(
MultiValueMap<? extends K, ? extends V> targetMap) {

Assert.notNull(targetMap, "'targetMap' must not be null");
Map<K, List<V>> result = newLinkedHashMap(targetMap.size());
targetMap.forEach((key, value) -> {
List<? extends V> values = Collections.unmodifiableList(value);
result.put(key, (List<V>) values);
});
Map<K, List<V>> unmodifiableMap = Collections.unmodifiableMap(result);
return toMultiValueMap(unmodifiableMap);
if (targetMap instanceof UnmodifiableMultiValueMap) {
return (MultiValueMap<K, V>) targetMap;
}
return new UnmodifiableMultiValueMap<>(targetMap);
}


Expand Down
Loading

0 comments on commit af4e677

Please sign in to comment.