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 * @since 3.1
*/ */
public static <K, V> MultiValueMap<K, V> toMultiValueMap(Map<K, List<V>> targetMap) { 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); return new MultiValueMapAdapter<>(targetMap);
} }

View File

@ -35,7 +35,8 @@ import java.util.Map;
* @param <K> the key type * @param <K> the key type
* @param <V> the value element 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; private static final long serialVersionUID = 3801124242820219131L;

View File

@ -30,23 +30,30 @@ import org.springframework.lang.Nullable;
* *
* @author Arjen Poutsma * @author Arjen Poutsma
* @author Juergen Hoeller * @author Juergen Hoeller
* @since 3.1 * @since 5.3
* @param <K> the key type * @param <K> the key type
* @param <V> the value element type * @param <V> the value element type
* @see CollectionUtils#toMultiValueMap * @see CollectionUtils#toMultiValueMap
* @see LinkedMultiValueMap * @see LinkedMultiValueMap
*/ */
@SuppressWarnings("serial") @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; 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; this.targetMap = targetMap;
} }
// MultiValueMap implementation
@Override @Override
@Nullable @Nullable
public V getFirst(K key) { public V getFirst(K key) {
@ -96,6 +103,9 @@ class MultiValueMapAdapter<K, V> implements MultiValueMap<K, V>, Serializable {
return singleValueMap; return singleValueMap;
} }
// Map implementation
@Override @Override
public int size() { public int size() {
return this.targetMap.size(); return this.targetMap.size();