Class CollectionFactory
Mainly for internal use within the framework.
- Since:
- 1.1.1
- Author:
- Juergen Hoeller, Arjen Poutsma, Oliver Gierke, Sam Brannen
- 
Method SummaryModifier and TypeMethodDescriptionstatic <E> Collection<E> createApproximateCollection(@Nullable Object collection, int capacity) Create the most approximate collection for the given collection.static <K,V> Map <K, V> createApproximateMap(@Nullable Object map, int capacity) Create the most approximate map for the given map.static <E> Collection<E> createCollection(Class<?> collectionType, int capacity) Create the most appropriate collection for the given collection type.static <E> Collection<E> createCollection(Class<?> collectionType, @Nullable Class<?> elementType, int capacity) Create the most appropriate collection for the given collection type.static <K,V> Map <K, V> Create the most appropriate map for the given map type.static <K,V> Map <K, V> Create the most appropriate map for the given map type.static PropertiescreateSortedProperties(boolean omitComments) Create a variant ofPropertiesthat sorts properties alphanumerically based on their keys.static PropertiescreateSortedProperties(Properties properties, boolean omitComments) Create a variant ofPropertiesthat sorts properties alphanumerically based on their keys.static PropertiesCreate a variant ofPropertiesthat automatically adapts non-String values to String representations inProperties.getProperty(java.lang.String).static booleanisApproximableCollectionType(@Nullable Class<?> collectionType) Determine whether the given collection type is an approximable type, i.e.static booleanisApproximableMapType(@Nullable Class<?> mapType) Determine whether the given map type is an approximable type, i.e.
- 
Method Details- 
isApproximableCollectionTypeDetermine 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:
- trueif the type is approximable
 
- 
createApproximateCollectionpublic static <E> Collection<E> createApproximateCollection(@Nullable Object collection, int capacity) Create the most approximate collection for the given collection.Warning: Since the parameterized type Eis not bound to the type of elements contained in the suppliedcollection, type safety cannot be guaranteed if the suppliedcollectionis anEnumSet. In such scenarios, the caller is responsible for ensuring that the element type for the suppliedcollectionis an enum type matching typeE. As an alternative, the caller may wish to treat the return value as a raw collection or collection ofObject.- Parameters:
- collection- the original collection object, potentially- null
- capacity- the initial capacity
- Returns:
- a new, empty collection instance
- See Also:
 
- 
createCollectionCreate the most appropriate collection for the given collection type.Delegates to createCollection(Class, Class, int)with anullelement type.- Parameters:
- collectionType- the desired type of the target collection (never- null)
- capacity- the initial capacity
- Returns:
- a new collection instance
- Throws:
- IllegalArgumentException- if the supplied- collectionTypeis- nullor of type- EnumSet
 
- 
createCollectionpublic static <E> Collection<E> createCollection(Class<?> collectionType, @Nullable Class<?> elementType, int capacity) Create the most appropriate collection for the given collection type.Warning: Since the parameterized type Eis not bound to the suppliedelementType, type safety cannot be guaranteed if the desiredcollectionTypeisEnumSet. In such scenarios, the caller is responsible for ensuring that the suppliedelementTypeis an enum type matching typeE. As an alternative, the caller may wish to treat the return value as a raw collection or collection ofObject.- Parameters:
- collectionType- the desired type of the target collection (never- null)
- elementType- the collection's element type, or- nullif unknown (note: only relevant for- EnumSetcreation)
- capacity- the initial capacity
- Returns:
- a new collection instance
- Throws:
- IllegalArgumentException- if the supplied- collectionTypeis- null; or if the desired- collectionTypeis- EnumSetand the supplied- elementTypeis not a subtype of- Enum
- Since:
- 4.1.3
- See Also:
 
- 
isApproximableMapTypeDetermine 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:
- trueif the type is approximable
 
- 
createApproximateMapCreate the most approximate map for the given map.Warning: Since the parameterized type Kis not bound to the type of keys contained in the suppliedmap, type safety cannot be guaranteed if the suppliedmapis anEnumMap. In such scenarios, the caller is responsible for ensuring that the key type in the suppliedmapis an enum type matching typeK. As an alternative, the caller may wish to treat the return value as a raw map or map keyed byObject.- Parameters:
- map- the original map object, potentially- null
- capacity- the initial capacity
- Returns:
- a new, empty map instance
- See Also:
 
- 
createMapCreate the most appropriate map for the given map type.Delegates to createMap(Class, Class, int)with anullkey type.- Parameters:
- mapType- the desired type of the target map
- capacity- the initial capacity
- Returns:
- a new map instance
- Throws:
- IllegalArgumentException- if the supplied- mapTypeis- nullor of type- EnumMap
 
- 
createMapCreate the most appropriate map for the given map type.Warning: Since the parameterized type Kis not bound to the suppliedkeyType, type safety cannot be guaranteed if the desiredmapTypeisEnumMap. In such scenarios, the caller is responsible for ensuring that thekeyTypeis an enum type matching typeK. As an alternative, the caller may wish to treat the return value as a raw map or map keyed byObject. Similarly, type safety cannot be enforced if the desiredmapTypeisMultiValueMap.- Parameters:
- mapType- the desired type of the target map (never- null)
- keyType- the map's key type, or- nullif unknown (note: only relevant for- EnumMapcreation)
- capacity- the initial capacity
- Returns:
- a new map instance
- Throws:
- IllegalArgumentException- if the supplied- mapTypeis- null; or if the desired- mapTypeis- EnumMapand the supplied- keyTypeis not a subtype of- Enum
- Since:
- 4.1.3
- See Also:
 
- 
createStringAdaptingPropertiesCreate a variant ofPropertiesthat automatically adapts non-String values to String representations inProperties.getProperty(java.lang.String).In addition, the returned Propertiesinstance sorts properties alphanumerically based on their keys.- Returns:
- a new Propertiesinstance
- Since:
- 4.3.4
- See Also:
 
- 
createSortedPropertiesCreate a variant ofPropertiesthat sorts properties alphanumerically based on their keys.This can be useful when storing the Propertiesinstance in a properties file, since it allows such files to be generated in a repeatable manner with consistent ordering of properties. Comments in generated properties files can also be optionally omitted.- Parameters:
- omitComments-- trueif comments should be omitted when storing properties in a file
- Returns:
- a new Propertiesinstance
- Since:
- 5.2
- See Also:
 
- 
createSortedPropertiesCreate a variant ofPropertiesthat sorts properties alphanumerically based on their keys.This can be useful when storing the Propertiesinstance in a properties file, since it allows such files to be generated in a repeatable manner with consistent ordering of properties. Comments in generated properties files can also be optionally omitted.The returned Propertiesinstance will be populated with properties from the suppliedpropertiesobject, but default properties from the suppliedpropertiesobject will not be copied.- Parameters:
- properties- the- Propertiesobject from which to copy the initial properties
- omitComments-- trueif comments should be omitted when storing properties in a file
- Returns:
- a new Propertiesinstance
- Since:
- 5.2
- See Also:
 
 
-