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

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static <E> Collection<E>` | `createApproximateCollection(Object collection, int initialCapacity)` Create the most approximate collection for the given collection.
    `static <K,V> Map<K,V>` | `createApproximateMap(Object map, int initialCapacity)` Create the most approximate map for the given map.
    `static <E> Collection<E>` | `createCollection(Class<?> collectionType, int initialCapacity)` Create the most appropriate collection for the given collection type.
    `static <K,V> Map<K,V>` | `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.

    - ### 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

    - #### isApproximableCollectionType

          public static boolean isApproximableCollectionType(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 <E> Collection<E> 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 <E> Collection<E> 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 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 <K,V> Map<K,V> 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 <K,V> Map<K,V> 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`