public abstract class CollectionFactory extends Object
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.
Constructor and Description |
---|
CollectionFactory() |
Modifier and Type | Method and Description |
---|---|
static <E> Collection<E> |
createApproximateCollection(Object collection,
int capacity)
Create the most approximate collection for the given collection.
|
static <K,V> Map<K,V> |
createApproximateMap(Object map,
int capacity)
Create the most approximate map for the given map.
|
static <E> Collection<E> |
createCollection(Class<?> collectionType,
Class<?> elementType,
int capacity)
Create the most appropriate collection for the given collection type.
|
static <E> Collection<E> |
createCollection(Class<?> collectionType,
int capacity)
Create the most appropriate collection for the given collection type.
|
static <K,V> Map<K,V> |
createMap(Class<?> mapType,
Class<?> keyType,
int capacity)
Create the most appropriate map for the given map type.
|
static <K,V> Map<K,V> |
createMap(Class<?> mapType,
int capacity)
Create the most appropriate map for the given map type.
|
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.
|
public static boolean isApproximableCollectionType(Class<?> collectionType)
createApproximateCollection(java.lang.Object, int)
can approximate.collectionType
- the collection type to checktrue
if the type is approximablepublic static <E> Collection<E> createApproximateCollection(Object collection, int capacity)
collection
- the original collection objectcapacity
- the initial capacityisApproximableCollectionType(java.lang.Class<?>)
,
LinkedList
,
ArrayList
,
EnumSet
,
TreeSet
,
LinkedHashSet
public static <E> Collection<E> createCollection(Class<?> collectionType, int capacity)
Delegates to createCollection(Class, Class, int)
with a
null
element type.
collectionType
- the desired type of the target collectioncapacity
- the initial capacitypublic static <E> Collection<E> createCollection(Class<?> collectionType, Class<?> elementType, int capacity)
collectionType
- the desired type of the target collection; never null
elementType
- the collection's element type, or null
if not known
(note: only relevant for EnumSet
creation)capacity
- the initial capacityLinkedHashSet
,
ArrayList
,
TreeSet
,
EnumSet
public static boolean isApproximableMapType(Class<?> mapType)
createApproximateMap(java.lang.Object, int)
can approximate.mapType
- the map type to checktrue
if the type is approximablepublic static <K,V> Map<K,V> createApproximateMap(Object map, int capacity)
map
- the original Map objectcapacity
- the initial capacityisApproximableMapType(java.lang.Class<?>)
,
EnumMap
,
TreeMap
,
LinkedHashMap
public static <K,V> Map<K,V> createMap(Class<?> mapType, int capacity)
Delegates to createMap(Class, Class, int)
with a
null
key type.
mapType
- the desired type of the target Mapcapacity
- the initial capacitypublic static <K,V> Map<K,V> createMap(Class<?> mapType, Class<?> keyType, int capacity)
mapType
- the desired type of the target MapkeyType
- the map's key type, or null
if not known
(note: only relevant for EnumMap
creation)capacity
- the initial capacityLinkedHashMap
,
TreeMap
,
LinkedMultiValueMap
,
EnumMap