public abstract class CollectionFactory
extends java.lang.Object
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.
Modifier and Type | Field and Description |
---|---|
private static java.util.Set<java.lang.Class<?>> |
approximableCollectionTypes |
private static java.util.Set<java.lang.Class<?>> |
approximableMapTypes |
Constructor and Description |
---|
CollectionFactory() |
Modifier and Type | Method and Description |
---|---|
static <E> java.util.Collection<E> |
createApproximateCollection(java.lang.Object collection,
int capacity)
Create the most approximate collection for the given collection.
|
static <K,V> java.util.Map<K,V> |
createApproximateMap(java.lang.Object map,
int capacity)
Create the most approximate map for the given map.
|
static <E> java.util.Collection<E> |
createCollection(java.lang.Class<?> collectionClass,
java.lang.Class<?> elementType,
int capacity)
Create the most appropriate collection for the given collection type.
|
static <E> java.util.Collection<E> |
createCollection(java.lang.Class<?> collectionClass,
int capacity)
Create the most appropriate collection for the given collection type.
|
static <K,V> java.util.Map<K,V> |
createMap(java.lang.Class<?> mapClass,
java.lang.Class<?> keyType,
int capacity)
Create the most approximate map for the given map.
|
static <K,V> java.util.Map<K,V> |
createMap(java.lang.Class<?> mapClass,
int capacity)
Create the most approximate map for the given map.
|
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.
|
private static final java.util.Set<java.lang.Class<?>> approximableCollectionTypes
private static final java.util.Set<java.lang.Class<?>> approximableMapTypes
public static boolean isApproximableCollectionType(java.lang.Class<?> collectionType)
createApproximateCollection(java.lang.Object, int)
can approximate.collectionType
- the collection type to checktrue
if the type is approximable,
false
if it is notpublic static <E> java.util.Collection<E> createApproximateCollection(java.lang.Object collection, int capacity)
collection
- the original Collection objectcapacity
- the initial capacityLinkedHashSet
,
TreeSet
,
EnumSet
,
ArrayList
,
LinkedList
public static <E> java.util.Collection<E> createCollection(java.lang.Class<?> collectionClass, int capacity)
Delegates to createCollection(Class, Class, int)
with a
null
element type.
collectionClass
- the desired type of the target Collectioncapacity
- the initial capacitypublic static <E> java.util.Collection<E> createCollection(java.lang.Class<?> collectionClass, java.lang.Class<?> elementType, int capacity)
collectionClass
- the desired type of the target CollectionelementType
- the collection's element type, or null
if not known
(note: only relevant for EnumSet
creation)capacity
- the initial capacityLinkedHashSet
,
TreeSet
,
EnumSet
,
ArrayList
public static boolean isApproximableMapType(java.lang.Class<?> mapType)
createApproximateMap(java.lang.Object, int)
can approximate.mapType
- the map type to checktrue
if the type is approximable,
false
if it is notpublic static <K,V> java.util.Map<K,V> createApproximateMap(java.lang.Object map, int capacity)
map
- the original Map objectcapacity
- the initial capacityTreeMap
,
LinkedHashMap
public static <K,V> java.util.Map<K,V> createMap(java.lang.Class<?> mapClass, int capacity)
Delegates to createMap(Class, Class, int)
with a
null
key type.
mapClass
- the desired type of the target Mapcapacity
- the initial capacitypublic static <K,V> java.util.Map<K,V> createMap(java.lang.Class<?> mapClass, java.lang.Class<?> keyType, int capacity)
mapClass
- 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
,
EnumMap
,
LinkedMultiValueMap