Skip to content

Commit 9bf82dc

Browse files
committed
Add addAll(MultiValueMap)
This commit introduces a new method for MultiValueMap: addAll, which adds all values of a given map (cf putAll, which replaces existing values).
1 parent 7085a30 commit 9bf82dc

File tree

5 files changed

+35
-0
lines changed

5 files changed

+35
-0
lines changed

spring-core/src/main/java/org/springframework/util/CollectionUtils.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,13 @@ public void addAll(K key, List<? extends V> values) {
422422
currentValues.addAll(values);
423423
}
424424

425+
@Override
426+
public void addAll(MultiValueMap<K, V> values) {
427+
for (Entry<K, List<V>> entry : values.entrySet()) {
428+
addAll(entry.getKey(), entry.getValue());
429+
}
430+
}
431+
425432
@Override
426433
public void set(K key, V value) {
427434
List<V> values = new LinkedList<>();

spring-core/src/main/java/org/springframework/util/LinkedMultiValueMap.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ public void addAll(K key, List<? extends V> values) {
9393
currentValues.addAll(values);
9494
}
9595

96+
@Override
97+
public void addAll(MultiValueMap<K, V> values) {
98+
for (Entry<K, List<V>> entry : values.entrySet()) {
99+
addAll(entry.getKey(), entry.getValue());
100+
}
101+
}
102+
96103
@Override
97104
public void set(K key, V value) {
98105
List<V> values = new LinkedList<>();

spring-core/src/main/java/org/springframework/util/MultiValueMap.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ public interface MultiValueMap<K, V> extends Map<K, List<V>> {
5252
*/
5353
void addAll(K key, List<? extends V> values);
5454

55+
/**
56+
* Add all the values of the given {@code MultiValueMap} to the current values.
57+
* @param values the values to be added
58+
* @since 5.0
59+
*/
60+
void addAll(MultiValueMap<K, V> values);
61+
5562
/**
5663
* Set the given single value under the given key.
5764
* @param key the key

spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompHeaders.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,13 @@ public void addAll(String headerName, List<? extends String> headerValues) {
422422
currentValues.addAll(headerValues);
423423
}
424424

425+
@Override
426+
public void addAll(MultiValueMap<String, String> values) {
427+
for (Entry<String, List<String>> entry : values.entrySet()) {
428+
addAll(entry.getKey(), entry.getValue());
429+
}
430+
}
431+
425432
/**
426433
* Set the given, single header value under the given name.
427434
* @param headerName the header name

spring-web/src/main/java/org/springframework/http/HttpHeaders.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,6 +1357,13 @@ public void addAll(String key, List<? extends String> values) {
13571357
currentValues.addAll(values);
13581358
}
13591359

1360+
@Override
1361+
public void addAll(MultiValueMap<String, String> values) {
1362+
for (Entry<String, List<String>> entry : values.entrySet()) {
1363+
addAll(entry.getKey(), entry.getValue());
1364+
}
1365+
}
1366+
13601367
/**
13611368
* Set the given, single header value under the given name.
13621369
* @param headerName the header name

0 commit comments

Comments
 (0)