org.springframework.core
Class CollectionFactory
- java.lang.Object
-
- org.springframework.core.CollectionFactory
public abstract class CollectionFactory extends Object
Factory for collections, being aware of Java 5 and Java 6 collections. Mainly for internal use within the framework.The goal of this class is to avoid runtime dependencies on a specific Java version, while nevertheless using the best collection implementation that is available at runtime.
- Since:
- 1.1.1
- Author:
- Juergen Hoeller, Arjen Poutsma
-
Constructor Summary
Constructors Constructor and Description CollectionFactory()
Method Summary
Methods Modifier and Type Method and Description static Collection
createApproximateCollection(Object collection, int initialCapacity)
Create the most approximate collection for the given collection.static Map
createApproximateMap(Object map, int initialCapacity)
Create the most approximate map for the given map.static Collection
createCollection(Class<?> collectionType, int initialCapacity)
Create the most appropriate collection for the given collection type.static ConcurrentMap
createConcurrentMap(int initialCapacity)
Deprecated.as of Spring 3.0, for usage on JDK 1.5 or higherstatic Map
createConcurrentMapIfPossible(int initialCapacity)
Deprecated.as of Spring 3.0, for usage on JDK 1.5 or higherstatic <T> Set<T>
createCopyOnWriteSet()
Deprecated.as of Spring 3.0, for usage on JDK 1.5 or higherstatic Map
createIdentityMapIfPossible(int initialCapacity)
Deprecated.as of Spring 2.5, for usage on JDK 1.4 or higherstatic Map
createLinkedCaseInsensitiveMapIfPossible(int initialCapacity)
Deprecated.as of Spring 3.0, for usage on JDK 1.5 or higherstatic <K,V> Map<K,V>
createLinkedMapIfPossible(int initialCapacity)
Deprecated.as of Spring 2.5, for usage on JDK 1.4 or higherstatic <T> Set<T>
createLinkedSetIfPossible(int initialCapacity)
Deprecated.as of Spring 2.5, for usage on JDK 1.4 or higherstatic Map
createMap(Class<?> mapType, int initialCapacity)
Create the most approximate map for the given map.static boolean
isApproximableCollectionType(Class<?> collectionType)
Determine whether the given collection type is an approximable type, i.e.static boolean
isApproximableMapType(Class<?> mapType)
Determine whether the given map type is an approximable type, i.e.
-
Method Detail
createLinkedSetIfPossible
@Deprecated public static <T> Set<T> createLinkedSetIfPossible(int initialCapacity)
Deprecated. as of Spring 2.5, for usage on JDK 1.4 or higherCreate a linked Set if possible: This implementation always creates aLinkedHashSet
, since Spring 2.5 requires JDK 1.4 anyway.- Parameters:
-
initialCapacity
- the initial capacity of the Set - Returns:
- the new Set instance
createCopyOnWriteSet
@Deprecated public static <T> Set<T> createCopyOnWriteSet()
Deprecated. as of Spring 3.0, for usage on JDK 1.5 or higherCreate a copy-on-write Set (allowing for synchronization-less iteration) if possible: This implementation always creates aCopyOnWriteArraySet
, since Spring 3 requires JDK 1.5 anyway.- Returns:
- the new Set instance
createLinkedMapIfPossible
@Deprecated public static <K,V> Map<K,V> createLinkedMapIfPossible(int initialCapacity)
Deprecated. as of Spring 2.5, for usage on JDK 1.4 or higherCreate a linked Map if possible: This implementation always creates aLinkedHashMap
, since Spring 2.5 requires JDK 1.4 anyway.- Parameters:
-
initialCapacity
- the initial capacity of the Map - Returns:
- the new Map instance
createLinkedCaseInsensitiveMapIfPossible
@Deprecated public static Map createLinkedCaseInsensitiveMapIfPossible(int initialCapacity)
Deprecated. as of Spring 3.0, for usage on JDK 1.5 or higherCreate a linked case-insensitive Map if possible: This implementation always returns aLinkedCaseInsensitiveMap
.- Parameters:
-
initialCapacity
- the initial capacity of the Map - Returns:
- the new Map instance
createIdentityMapIfPossible
@Deprecated public static Map createIdentityMapIfPossible(int initialCapacity)
Deprecated. as of Spring 2.5, for usage on JDK 1.4 or higherCreate an identity Map if possible: This implementation always creates aIdentityHashMap
, since Spring 2.5 requires JDK 1.4 anyway.- Parameters:
-
initialCapacity
- the initial capacity of the Map - Returns:
- the new Map instance
createConcurrentMapIfPossible
@Deprecated public static Map createConcurrentMapIfPossible(int initialCapacity)
Deprecated. as of Spring 3.0, for usage on JDK 1.5 or higherCreate a concurrent Map if possible: This implementation always creates aConcurrentHashMap
, since Spring 3.0 requires JDK 1.5 anyway.- Parameters:
-
initialCapacity
- the initial capacity of the Map - Returns:
- the new Map instance
createConcurrentMap
@Deprecated public static ConcurrentMap createConcurrentMap(int initialCapacity)
Deprecated. as of Spring 3.0, for usage on JDK 1.5 or higherCreate a concurrent Map with a dedicatedConcurrentMap
interface: This implementation always creates aConcurrentHashMap
, since Spring 3.0 requires JDK 1.5 anyway.- Parameters:
-
initialCapacity
- the initial capacity of the Map - Returns:
- the new ConcurrentMap instance
isApproximableCollectionType
public static boolean isApproximableCollectionType(Class<?> collectionType)
Determine whether the given collection type is an approximable type, i.e. a type thatcreateApproximateCollection(java.lang.Object, int)
can approximate.- Parameters:
-
collectionType
- the collection type to check - Returns:
-
true
if the type is approximable,false
if it is not
createApproximateCollection
public static Collection createApproximateCollection(Object collection, int initialCapacity)
Create the most approximate collection for the given collection.Creates an ArrayList, TreeSet or linked Set for a List, SortedSet or Set, respectively.
- Parameters:
-
collection
- the original Collection object -
initialCapacity
- the initial capacity - Returns:
- the new Collection instance
- See Also:
-
ArrayList
,TreeSet
,LinkedHashSet
createCollection
public static Collection createCollection(Class<?> collectionType, int initialCapacity)
Create the most appropriate collection for the given collection type.Creates an ArrayList, TreeSet or linked Set for a List, SortedSet or Set, respectively.
- Parameters:
-
collectionType
- the desired type of the target Collection -
initialCapacity
- the initial capacity - Returns:
- the new Collection instance
- See Also:
-
ArrayList
,TreeSet
,LinkedHashSet
isApproximableMapType
public static boolean isApproximableMapType(Class<?> mapType)
Determine whether the given map type is an approximable type, i.e. a type thatcreateApproximateMap(java.lang.Object, int)
can approximate.- Parameters:
-
mapType
- the map type to check - Returns:
-
true
if the type is approximable,false
if it is not
createApproximateMap
public static Map createApproximateMap(Object map, int initialCapacity)
Create the most approximate map for the given map.Creates a TreeMap or linked Map for a SortedMap or Map, respectively.
- Parameters:
-
map
- the original Map object -
initialCapacity
- the initial capacity - Returns:
- the new Map instance
- See Also:
-
TreeMap
,LinkedHashMap
createMap
public static Map createMap(Class<?> mapType, int initialCapacity)
Create the most approximate map for the given map.Creates a TreeMap or linked Map for a SortedMap or Map, respectively.
- Parameters:
-
mapType
- the desired type of the target Map -
initialCapacity
- the initial capacity - Returns:
- the new Map instance
- See Also:
-
TreeMap
,LinkedHashMap