spring-framework / org.springframework.util / CollectionUtils

CollectionUtils

abstract class CollectionUtils

Miscellaneous collection utility methods. Mainly for internal use within the framework.

Author
Juergen Hoeller

Author
Rob Harrop

Author
Arjen Poutsma

Since
1.1.3

Constructors

<init>

CollectionUtils()

Miscellaneous collection utility methods. Mainly for internal use within the framework.

Functions

arrayToList

open static fun arrayToList(source: Any): MutableList<Any?>

Convert the supplied array into a List. A primitive array gets converted into a List of the appropriate wrapper type.

NOTE: Generally prefer the standard Arrays#asList method. This arrayToList method is just meant to deal with an incoming Object value that might be an Object[] or a primitive array at runtime.

A null source value will be converted to an empty List.

contains

open static fun contains(iterator: MutableIterator<*>, element: Any): Boolean

Check whether the given Iterator contains the given element.

open static fun contains(enumeration: Enumeration<*>, element: Any): Boolean

Check whether the given Enumeration contains the given element.

containsAny

open static fun containsAny(source: MutableCollection<*>, candidates: MutableCollection<*>): Boolean

Return true if any element in 'candidates' is contained in 'source'; otherwise returns false.

containsInstance

open static fun containsInstance(collection: MutableCollection<*>, element: Any): Boolean

Check whether the given Collection contains the given element instance.

Enforces the given instance to be present, rather than returning true for an equal element as well.

findCommonElementType

open static fun findCommonElementType(collection: MutableCollection<*>): Class<*>

Find the common element type of the given Collection, if any.

findFirstMatch

open static fun <E : Any> findFirstMatch(source: MutableCollection<*>, candidates: MutableCollection<E>): E

Return the first element in 'candidates' that is contained in 'source'. If no element in 'candidates' is present in 'source' returns null. Iteration order is Collection implementation specific.

findValueOfType

open static fun <T : Any> findValueOfType(collection: MutableCollection<*>, type: Class<T>): T

Find a single value of the given type in the given Collection.

open static fun findValueOfType(collection: MutableCollection<*>, types: Array<Class<*>>): Any

Find a single value of one of the given types in the given Collection: searching the Collection for a value of the first type, then searching for a value of the second type, etc.

hasUniqueObject

open static fun hasUniqueObject(collection: MutableCollection<*>): Boolean

Determine whether the given Collection only contains a single unique object.

isEmpty

open static fun isEmpty(collection: MutableCollection<*>): Boolean

Return true if the supplied Collection is null or empty. Otherwise, return false.

open static fun isEmpty(map: MutableMap<*, *>): Boolean

Return true if the supplied Map is null or empty. Otherwise, return false.

mergeArrayIntoCollection

open static fun <E : Any> mergeArrayIntoCollection(array: Any, collection: MutableCollection<E>): Unit

Merge the given array into the given Collection.

mergePropertiesIntoMap

open static fun <K : Any, V : Any> mergePropertiesIntoMap(props: Properties, map: MutableMap<K, V>): Unit

Merge the given Properties instance into the given Map, copying all properties (key-value pairs) over.

Uses Properties.propertyNames() to even catch default properties linked into the original Properties instance.

toArray

open static fun <A : Any, E : A> toArray(enumeration: Enumeration<E>, array: Array<A>): Array<A>

Marshal the elements from the given enumeration into an array of the given type. Enumeration elements must be assignable to the type of the given array. The array returned will be a different instance than the array given.

toIterator

open static fun <E : Any> toIterator(enumeration: Enumeration<E>): MutableIterator<E>

Adapt an enumeration to an iterator.

toMultiValueMap

open static fun <K : Any, V : Any> toMultiValueMap(map: MutableMap<K, MutableList<V>>): MultiValueMap<K, V>

Adapt a Map<K, List<V>> to an MultiValueMap<K, V>.

unmodifiableMultiValueMap

open static fun <K : Any, V : Any> unmodifiableMultiValueMap(map: MultiValueMap<out K, out V>): MultiValueMap<K, V>

Return an unmodifiable view of the specified multi-value map.