Browse Source

CollectionFactory should be aware of MultiValueMap

Issue: SPR-9498
3.1.x
Juergen Hoeller 14 years ago
parent
commit
52c10c52cd
  1. 7
      org.springframework.core/src/main/java/org/springframework/core/CollectionFactory.java
  2. 10
      org.springframework.core/src/test/java/org/springframework/core/CollectionFactoryTests.java

7
org.springframework.core/src/main/java/org/springframework/core/CollectionFactory.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -35,6 +35,8 @@ import java.util.concurrent.ConcurrentHashMap; @@ -35,6 +35,8 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArraySet;
import org.springframework.util.LinkedCaseInsensitiveMap;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
/**
* Factory for collections, being aware of Java 5 and Java 6 collections.
@ -305,6 +307,9 @@ public abstract class CollectionFactory { @@ -305,6 +307,9 @@ public abstract class CollectionFactory {
else if (SortedMap.class.equals(mapType) || mapType.equals(navigableMapClass)) {
return new TreeMap();
}
else if (MultiValueMap.class.equals(mapType)) {
return new LinkedMultiValueMap();
}
else {
throw new IllegalArgumentException("Unsupported Map interface: " + mapType.getName());
}

10
org.springframework.core/src/test/java/org/springframework/core/CollectionFactoryTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -24,9 +24,12 @@ import java.util.Set; @@ -24,9 +24,12 @@ import java.util.Set;
import junit.framework.TestCase;
import org.springframework.util.MultiValueMap;
/**
* @author Darren Davison
* @author Juergen Hoeller
* @author Dave Syer
*/
public class CollectionFactoryTests extends TestCase {
@ -50,6 +53,11 @@ public class CollectionFactoryTests extends TestCase { @@ -50,6 +53,11 @@ public class CollectionFactoryTests extends TestCase {
assertTrue(map.getClass().getName().endsWith("ConcurrentHashMap"));
}
public void testMultiValueMap() {
Map map = CollectionFactory.createMap(MultiValueMap.class, 16);
assertTrue(map.getClass().getName().endsWith("MultiValueMap"));
}
public void testConcurrentMapWithExplicitInterface() {
ConcurrentMap map = CollectionFactory.createConcurrentMap(16);
assertTrue(map.getClass().getSuperclass().getName().endsWith("ConcurrentHashMap"));

Loading…
Cancel
Save