类 CollectionFactory


  • public abstract class CollectionFactory
    extends Object
    Factory for collections that is aware of Java 5, Java 6, and Spring collection types.

    Mainly for internal use within the framework.

    从以下版本开始:
    1.1.1
    作者:
    Juergen Hoeller, Arjen Poutsma, Oliver Gierke, Sam Brannen
    • 方法详细资料

      • createApproximateCollection

        public static <E> Collection<E> createApproximateCollection​(Object collection,
                                                                    int capacity)
        Create the most approximate collection for the given collection.

        Warning: Since the parameterized type E is not bound to the type of elements contained in the supplied collection, type safety cannot be guaranteed if the supplied collection is an EnumSet. In such scenarios, the caller is responsible for ensuring that the element type for the supplied collection is an enum type matching type E. As an alternative, the caller may wish to treat the return value as a raw collection or collection of Object.

        参数:
        collection - the original collection object, potentially null
        capacity - the initial capacity
        返回:
        a new, empty collection instance
        另请参阅:
        isApproximableCollectionType(java.lang.Class<?>), LinkedList, ArrayList, EnumSet, TreeSet, LinkedHashSet
      • createCollection

        public static <E> Collection<E> createCollection​(Class<?> collectionType,
                                                         int capacity)
        Create the most appropriate collection for the given collection type.

        Delegates to createCollection(Class, Class, int) with a null element type.

        参数:
        collectionType - the desired type of the target collection; never null
        capacity - the initial capacity
        返回:
        a new collection instance
        抛出:
        IllegalArgumentException - if the supplied collectionType is null or of type EnumSet
      • createCollection

        public static <E> Collection<E> createCollection​(Class<?> collectionType,
                                                         Class<?> elementType,
                                                         int capacity)
        Create the most appropriate collection for the given collection type.

        Warning: Since the parameterized type E is not bound to the supplied elementType, type safety cannot be guaranteed if the desired collectionType is EnumSet. In such scenarios, the caller is responsible for ensuring that the supplied elementType is an enum type matching type E. As an alternative, the caller may wish to treat the return value as a raw collection or collection of Object.

        参数:
        collectionType - the desired type of the target collection; never null
        elementType - the collection's element type, or null if unknown (note: only relevant for EnumSet creation)
        capacity - the initial capacity
        返回:
        a new collection instance
        抛出:
        IllegalArgumentException - if the supplied collectionType is null; or if the desired collectionType is EnumSet and the supplied elementType is not a subtype of Enum
        从以下版本开始:
        4.1.3
        另请参阅:
        LinkedHashSet, ArrayList, TreeSet, EnumSet
      • createApproximateMap

        public static <K,​V> Map<K,​V> createApproximateMap​(Object map,
                                                                      int capacity)
        Create the most approximate map for the given map.

        Warning: Since the parameterized type K is not bound to the type of keys contained in the supplied map, type safety cannot be guaranteed if the supplied map is an EnumMap. In such scenarios, the caller is responsible for ensuring that the key type in the supplied map is an enum type matching type K. As an alternative, the caller may wish to treat the return value as a raw map or map keyed by Object.

        参数:
        map - the original map object, potentially null
        capacity - the initial capacity
        返回:
        a new, empty map instance
        另请参阅:
        isApproximableMapType(java.lang.Class<?>), EnumMap, TreeMap, LinkedHashMap
      • createMap

        public static <K,​V> Map<K,​V> createMap​(Class<?> mapType,
                                                           int capacity)
        Create the most appropriate map for the given map type.

        Delegates to createMap(Class, Class, int) with a null key type.

        参数:
        mapType - the desired type of the target map
        capacity - the initial capacity
        返回:
        a new map instance
        抛出:
        IllegalArgumentException - if the supplied mapType is null or of type EnumMap
      • createMap

        public static <K,​V> Map<K,​V> createMap​(Class<?> mapType,
                                                           Class<?> keyType,
                                                           int capacity)
        Create the most appropriate map for the given map type.

        Warning: Since the parameterized type K is not bound to the supplied keyType, type safety cannot be guaranteed if the desired mapType is EnumMap. In such scenarios, the caller is responsible for ensuring that the keyType is an enum type matching type K. As an alternative, the caller may wish to treat the return value as a raw map or map keyed by Object. Similarly, type safety cannot be enforced if the desired mapType is MultiValueMap.

        参数:
        mapType - the desired type of the target map; never null
        keyType - the map's key type, or null if unknown (note: only relevant for EnumMap creation)
        capacity - the initial capacity
        返回:
        a new map instance
        抛出:
        IllegalArgumentException - if the supplied mapType is null; or if the desired mapType is EnumMap and the supplied keyType is not a subtype of Enum
        从以下版本开始:
        4.1.3
        另请参阅:
        LinkedHashMap, TreeMap, LinkedMultiValueMap, EnumMap