org.springframework.core
Class CollectionFactory

java.lang.Object
  extended by org.springframework.core.CollectionFactory

public abstract class CollectionFactory
extends java.lang.Object

Factory for collections, being aware of Commons Collection 3.x's extended collections as well as of JDK 1.5+ concurrent collections and backport-concurrent collections. Mainly for internal use within the framework.

The goal of this class is to avoid runtime dependencies on JDK 1.5+ and Commons Collections 3.x, simply using the best collection implementation that is available at runtime.

Since:
1.1.1
Author:
Juergen Hoeller, Arjen Poutsma

Constructor Summary
CollectionFactory()
           
 
Method Summary
static java.util.Collection createApproximateCollection(java.lang.Object collection, int initialCapacity)
          Create the most approximate collection for the given collection.
static java.util.Map createApproximateMap(java.lang.Object map, int initialCapacity)
          Create the most approximate map for the given map.
static ConcurrentMap createConcurrentMap(int initialCapacity)
          Deprecated. as of Spring 3.0, for usage on JDK 1.5 or higher
static java.util.Map createConcurrentMapIfPossible(int initialCapacity)
          Deprecated. as of Spring 3.0, for usage on JDK 1.5 or higher
static java.util.Set createCopyOnWriteSet()
          Deprecated. as of Spring 3.0, for usage on JDK 1.5 or higher
static java.util.Map createIdentityMapIfPossible(int initialCapacity)
          Deprecated. as of Spring 2.5, for usage on JDK 1.4 or higher
static java.util.Map createLinkedCaseInsensitiveMapIfPossible(int initialCapacity)
          Create a linked case-insensitive Map if possible: if Commons Collections 3.x is available, a CaseInsensitiveMap with ListOrderedMap decorator will be created.
static java.util.Map createLinkedMapIfPossible(int initialCapacity)
          Deprecated. as of Spring 2.5, for usage on JDK 1.4 or higher
static java.util.Set createLinkedSetIfPossible(int initialCapacity)
          Deprecated. as of Spring 2.5, for usage on JDK 1.4 or higher
static boolean isApproximableCollectionType(java.lang.Class collectionType)
          Determine whether the given collection type is an approximable type, i.e.
static boolean isApproximableMapType(java.lang.Class mapType)
          Determine whether the given map type is an approximable type, i.e.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CollectionFactory

public CollectionFactory()
Method Detail

createLinkedSetIfPossible

@Deprecated
public static java.util.Set createLinkedSetIfPossible(int initialCapacity)
Deprecated. as of Spring 2.5, for usage on JDK 1.4 or higher

Create a linked Set if possible: This implementation always creates a LinkedHashSet, 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 java.util.Set createCopyOnWriteSet()
Deprecated. as of Spring 3.0, for usage on JDK 1.5 or higher

Create a copy-on-write Set (allowing for synchronization-less iteration) if possible: This implementation always creates a CopyOnWriteArraySet, since Spring 3 requires JDK 1.5 anyway.

Returns:
the new Set instance

createLinkedMapIfPossible

@Deprecated
public static java.util.Map createLinkedMapIfPossible(int initialCapacity)
Deprecated. as of Spring 2.5, for usage on JDK 1.4 or higher

Create a linked Map if possible: This implementation always creates a LinkedHashMap, since Spring 2.5 requires JDK 1.4 anyway.

Parameters:
initialCapacity - the initial capacity of the Map
Returns:
the new Map instance

createLinkedCaseInsensitiveMapIfPossible

public static java.util.Map createLinkedCaseInsensitiveMapIfPossible(int initialCapacity)
Create a linked case-insensitive Map if possible: if Commons Collections 3.x is available, a CaseInsensitiveMap with ListOrderedMap decorator will be created. Else, a JDK LinkedHashMap will be used.

Parameters:
initialCapacity - the initial capacity of the Map
Returns:
the new Map instance
See Also:
CaseInsensitiveMap, ListOrderedMap

createIdentityMapIfPossible

@Deprecated
public static java.util.Map createIdentityMapIfPossible(int initialCapacity)
Deprecated. as of Spring 2.5, for usage on JDK 1.4 or higher

Create an identity Map if possible: This implementation always creates a IdentityHashMap, 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 java.util.Map createConcurrentMapIfPossible(int initialCapacity)
Deprecated. as of Spring 3.0, for usage on JDK 1.5 or higher

Create a concurrent Map if possible: This implementation always creates a ConcurrentHashMap, 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 higher

Create a concurrent Map with a dedicated ConcurrentMap interface: This implementation always creates a ConcurrentHashMap, 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(java.lang.Class collectionType)
Determine whether the given collection type is an approximable type, i.e. a type that createApproximateCollection(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 java.util.Collection createApproximateCollection(java.lang.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

isApproximableMapType

public static boolean isApproximableMapType(java.lang.Class mapType)
Determine whether the given map type is an approximable type, i.e. a type that createApproximateMap(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 java.util.Map createApproximateMap(java.lang.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 collection instance
See Also:
TreeMap, LinkedHashMap