Make MultiValueMapAdapter public (as base class for LinkedMultiValueMap)

Closes gh-25960
This commit is contained in:
Juergen Hoeller 2020-10-26 10:41:59 +01:00
parent a2ff03074f
commit a3f3a136c4
3 changed files with 15 additions and 5 deletions

View File

@ -457,7 +457,6 @@ public abstract class CollectionUtils {
* @since 3.1
*/
public static <K, V> MultiValueMap<K, V> toMultiValueMap(Map<K, List<V>> targetMap) {
Assert.notNull(targetMap, "'targetMap' must not be null");
return new MultiValueMapAdapter<>(targetMap);
}

View File

@ -35,7 +35,8 @@ import java.util.Map;
* @param <K> the key type
* @param <V> the value element type
*/
public class LinkedMultiValueMap<K, V> extends MultiValueMapAdapter<K, V> implements Serializable, Cloneable {
public class LinkedMultiValueMap<K, V> extends MultiValueMapAdapter<K, V> // new public base class in 5.3
implements Serializable, Cloneable {
private static final long serialVersionUID = 3801124242820219131L;

View File

@ -30,23 +30,30 @@ import org.springframework.lang.Nullable;
*
* @author Arjen Poutsma
* @author Juergen Hoeller
* @since 3.1
* @since 5.3
* @param <K> the key type
* @param <V> the value element type
* @see CollectionUtils#toMultiValueMap
* @see LinkedMultiValueMap
*/
@SuppressWarnings("serial")
class MultiValueMapAdapter<K, V> implements MultiValueMap<K, V>, Serializable {
public class MultiValueMapAdapter<K, V> implements MultiValueMap<K, V>, Serializable {
private final Map<K, List<V>> targetMap;
MultiValueMapAdapter(Map<K, List<V>> targetMap) {
/**
* Wrap the given target {@link Map} as a {@link MultiValueMap} adapter.
* @param targetMap the plain target {@code Map}
*/
public MultiValueMapAdapter(Map<K, List<V>> targetMap) {
Assert.notNull(targetMap, "'targetMap' must not be null");
this.targetMap = targetMap;
}
// MultiValueMap implementation
@Override
@Nullable
public V getFirst(K key) {
@ -96,6 +103,9 @@ class MultiValueMapAdapter<K, V> implements MultiValueMap<K, V>, Serializable {
return singleValueMap;
}
// Map implementation
@Override
public int size() {
return this.targetMap.size();