@ -54,9 +54,9 @@ import org.springframework.util.MultiValueMap;
@@ -54,9 +54,9 @@ import org.springframework.util.MultiValueMap;
* /
public abstract class CollectionFactory {
private static final Set < Class < ? > > approximableCollectionTypes = new HashSet < Class < ? > > ( 10 ) ;
private static final Set < Class < ? > > approximableCollectionTypes = new HashSet < Class < ? > > ( 11 ) ;
private static final Set < Class < ? > > approximableMapTypes = new HashSet < Class < ? > > ( 6 ) ;
private static final Set < Class < ? > > approximableMapTypes = new HashSet < Class < ? > > ( 7 ) ;
static {
@ -85,10 +85,10 @@ public abstract class CollectionFactory {
@@ -85,10 +85,10 @@ public abstract class CollectionFactory {
/ * *
* Determine whether the given collection type is an approximable type ,
* Determine whether the given collection type is an < em > approximable < / em > type ,
* i . e . a type that { @link # createApproximateCollection } can approximate .
* @param collectionType the collection type to check
* @return { @code true } if the type is approximable
* @return { @code true } if the type is < em > approximable < / em >
* /
public static boolean isApproximableCollectionType ( Class < ? > collectionType ) {
return ( collectionType ! = null & & approximableCollectionTypes . contains ( collectionType ) ) ;
@ -96,14 +96,15 @@ public abstract class CollectionFactory {
@@ -96,14 +96,15 @@ public abstract class CollectionFactory {
/ * *
* Create the most approximate collection for the given collection .
* @param collection the original C ollection object
* @param collection the original c ollection object
* @param capacity the initial capacity
* @return the new Collection instance
* @see java . util . LinkedHashSet
* @see java . util . TreeSet
* @see java . util . EnumSet
* @see java . util . ArrayList
* @return the new , empty collection instance
* @see # isApproximableCollectionType
* @see java . util . LinkedList
* @see java . util . ArrayList
* @see java . util . EnumSet
* @see java . util . TreeSet
* @see java . util . LinkedHashSet
* /
@SuppressWarnings ( { "unchecked" , "cast" , "rawtypes" } )
public static < E > Collection < E > createApproximateCollection ( Object collection , int capacity ) {
@ -114,9 +115,10 @@ public abstract class CollectionFactory {
@@ -114,9 +115,10 @@ public abstract class CollectionFactory {
return new ArrayList < E > ( capacity ) ;
}
else if ( collection instanceof EnumSet ) {
// superfluous cast necessary for bug in Eclipse 4.4.1.
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=454644
return ( Collection < E > ) EnumSet . copyOf ( ( EnumSet ) collection ) ;
// Cast is necessary for compilation in Eclipse 4.4.1.
Collection < E > enumSet = ( Collection < E > ) EnumSet . copyOf ( ( EnumSet ) collection ) ;
enumSet . clear ( ) ;
return enumSet ;
}
else if ( collection instanceof SortedSet ) {
return new TreeSet < E > ( ( ( SortedSet < E > ) collection ) . comparator ( ) ) ;
@ -130,9 +132,9 @@ public abstract class CollectionFactory {
@@ -130,9 +132,9 @@ public abstract class CollectionFactory {
* Create the most appropriate collection for the given collection type .
* < p > Delegates to { @link # createCollection ( Class , Class , int ) } with a
* { @code null } element type .
* @param collectionType the desired type of the target C ollection
* @param collectionType the desired type of the target c ollection
* @param capacity the initial capacity
* @return the new C ollection instance
* @return the new c ollection instance
* /
public static < E > Collection < E > createCollection ( Class < ? > collectionType , int capacity ) {
return createCollection ( collectionType , null , capacity ) ;
@ -140,16 +142,16 @@ public abstract class CollectionFactory {
@@ -140,16 +142,16 @@ public abstract class CollectionFactory {
/ * *
* Create the most appropriate collection for the given collection type .
* @param collectionType the desired type of the target C ollection; never { @code null }
* @param collectionType the desired type of the target c ollection; never { @code null }
* @param elementType the collection ' s element type , or { @code null } if not known
* ( note : only relevant for { @link EnumSet } creation )
* @param capacity the initial capacity
* @return the new C ollection instance
* @return the new c ollection instance
* @since 4 . 1 . 3
* @see java . util . LinkedHashSet
* @see java . util . ArrayList
* @see java . util . TreeSet
* @see java . util . EnumSet
* @see java . util . ArrayList
* /
@SuppressWarnings ( { "unchecked" , "cast" } )
public static < E > Collection < E > createCollection ( Class < ? > collectionType , Class < ? > elementType , int capacity ) {
@ -170,8 +172,7 @@ public abstract class CollectionFactory {
@@ -170,8 +172,7 @@ public abstract class CollectionFactory {
}
else if ( EnumSet . class . equals ( collectionType ) ) {
Assert . notNull ( elementType , "Cannot create EnumSet for unknown element type" ) ;
// superfluous cast necessary for bug in Eclipse 4.4.1.
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=454644
// Cast is necessary for compilation in Eclipse 4.4.1.
return ( Collection < E > ) EnumSet . noneOf ( asEnumType ( elementType ) ) ;
}
else {
@ -189,11 +190,10 @@ public abstract class CollectionFactory {
@@ -189,11 +190,10 @@ public abstract class CollectionFactory {
}
/ * *
* Determine whether the given map type is an approximable type ,
* Determine whether the given map type is an < em > approximable < / em > type ,
* i . e . a type that { @link # createApproximateMap } can approximate .
* @param mapType the map type to check
* @return { @code true } if the type is approximable ,
* { @code false } if it is not
* @return { @code true } if the type is < em > approximable < / em >
* /
public static boolean isApproximableMapType ( Class < ? > mapType ) {
return ( mapType ! = null & & approximableMapTypes . contains ( mapType ) ) ;
@ -203,14 +203,18 @@ public abstract class CollectionFactory {
@@ -203,14 +203,18 @@ public abstract class CollectionFactory {
* Create the most approximate map for the given map .
* @param map the original Map object
* @param capacity the initial capacity
* @return the new Map instance
* @return the new , empty Map instance
* @see # isApproximableMapType
* @see java . util . EnumMap
* @see java . util . TreeMap
* @see java . util . LinkedHashMap
* /
@SuppressWarnings ( { "unchecked" , "rawtypes" } )
public static < K , V > Map < K , V > createApproximateMap ( Object map , int capacity ) {
if ( map instanceof EnumMap ) {
return new EnumMap ( ( Map ) map ) ;
EnumMap enumMap = new EnumMap ( ( EnumMap ) map ) ;
enumMap . clear ( ) ;
return enumMap ;
}
else if ( map instanceof SortedMap ) {
return new TreeMap < K , V > ( ( ( SortedMap < K , V > ) map ) . comparator ( ) ) ;
@ -221,7 +225,7 @@ public abstract class CollectionFactory {
@@ -221,7 +225,7 @@ public abstract class CollectionFactory {
}
/ * *
* Create the most approxim ate map for the given map .
* Create the most appropri ate map for the given map type .
* < p > Delegates to { @link # createMap ( Class , Class , int ) } with a
* { @code null } key type .
* @param mapType the desired type of the target Map
@ -233,7 +237,7 @@ public abstract class CollectionFactory {
@@ -233,7 +237,7 @@ public abstract class CollectionFactory {
}
/ * *
* Create the most approxim ate map for the given map .
* Create the most appropri ate map for the given map type .
* @param mapType the desired type of the target Map
* @param keyType the map ' s key type , or { @code null } if not known
* ( note : only relevant for { @link EnumMap } creation )
@ -242,8 +246,8 @@ public abstract class CollectionFactory {
@@ -242,8 +246,8 @@ public abstract class CollectionFactory {
* @since 4 . 1 . 3
* @see java . util . LinkedHashMap
* @see java . util . TreeMap
* @see java . util . EnumMap
* @see org . springframework . util . LinkedMultiValueMap
* @see java . util . EnumMap
* /
@SuppressWarnings ( { "unchecked" , "rawtypes" } )
public static < K , V > Map < K , V > createMap ( Class < ? > mapType , Class < ? > keyType , int capacity ) {
@ -284,6 +288,7 @@ public abstract class CollectionFactory {
@@ -284,6 +288,7 @@ public abstract class CollectionFactory {
* @param enumType the enum type , never { @code null }
* @return the given type as subtype of { @link Enum }
* @throws IllegalArgumentException if the given type is not a subtype of { @link Enum }
* @since 4 . 1 . 4
* /
@SuppressWarnings ( "rawtypes" )
private static Class < ? extends Enum > asEnumType ( Class < ? > enumType ) {