SPR-9498: Add support for MultiValueMap to CollectionFactory
This turns out not to be the main problem exposed in SPR-9498 but it seems like a sensible addition anyway.
This commit is contained in:
@@ -35,6 +35,8 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
import java.util.concurrent.CopyOnWriteArraySet;
|
import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
|
|
||||||
import org.springframework.util.LinkedCaseInsensitiveMap;
|
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.
|
* Factory for collections, being aware of Java 5 and Java 6 collections.
|
||||||
@@ -305,6 +307,9 @@ public abstract class CollectionFactory {
|
|||||||
else if (SortedMap.class.equals(mapType) || mapType.equals(navigableMapClass)) {
|
else if (SortedMap.class.equals(mapType) || mapType.equals(navigableMapClass)) {
|
||||||
return new TreeMap();
|
return new TreeMap();
|
||||||
}
|
}
|
||||||
|
else if (MultiValueMap.class.equals(mapType)) {
|
||||||
|
return new LinkedMultiValueMap();
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
throw new IllegalArgumentException("Unsupported Map interface: " + mapType.getName());
|
throw new IllegalArgumentException("Unsupported Map interface: " + mapType.getName());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,9 +24,12 @@ import java.util.Set;
|
|||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import org.springframework.util.MultiValueMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Darren Davison
|
* @author Darren Davison
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
* @author Dave Syer
|
||||||
*/
|
*/
|
||||||
public class CollectionFactoryTests extends TestCase {
|
public class CollectionFactoryTests extends TestCase {
|
||||||
|
|
||||||
@@ -50,6 +53,11 @@ public class CollectionFactoryTests extends TestCase {
|
|||||||
assertTrue(map.getClass().getName().endsWith("ConcurrentHashMap"));
|
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() {
|
public void testConcurrentMapWithExplicitInterface() {
|
||||||
ConcurrentMap map = CollectionFactory.createConcurrentMap(16);
|
ConcurrentMap map = CollectionFactory.createConcurrentMap(16);
|
||||||
assertTrue(map.getClass().getSuperclass().getName().endsWith("ConcurrentHashMap"));
|
assertTrue(map.getClass().getSuperclass().getName().endsWith("ConcurrentHashMap"));
|
||||||
|
|||||||
Reference in New Issue
Block a user