Spring Data for VMware GemFire
Class CollectionUtils
java.lang.Object
org.springframework.util.CollectionUtils
org.springframework.data.gemfire.util.CollectionUtils
public abstract class CollectionUtils
extends org.springframework.util.CollectionUtils
Abstract utility class used to operate on Java Collections Framework and classes.
- Since:
- 1.7.0
- See Also:
-
CollectionCollectionsEnumerationIteratorListMapSetCollectionUtils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <E,T extends Collection<E>>
TAdds all elements from the givenIterableto theCollection.static <T> Set<T>asSet(T... elements) Returns an unmodifiableSetcontaining the elements from the given object array.static booleancontainsAny(Collection<?> collection, Object... elements) Null-safe method to determines whether the givenCollectioncontains any elements from the given array.static <T> Iterable<T>Returns an emptyIterableobject.static <T> Iterable<T>iterable(Enumeration<T> enumeration) Adapts the given Enumeration as an Iterable object for use within a for each loop.static <T> Iterable<T>Adapts the given Iterator as an Iterable object for use within a for each loop.static <T> Collection<T>nullSafeCollection(Collection<T> collection) Null-safe operation returning the givenCollectionif not null or an emptyCollection(implemented withList) if null.static <T> Enumeration<T>nullSafeEnumeration(Enumeration<T> enumeration) Null-safe operation returning the givenEnumerationif not null or anempty Enumerationif null.static booleannullSafeIsEmpty(Iterable<?> iterable) Determines whether the givenIterableis empty.static booleannullSafeIsEmpty(Collection<?> collection) Determines whether the givenCollectionisempty.static booleannullSafeIsEmpty(Map<?, ?> map) static <T> Iterable<T>nullSafeIterable(Iterable<T> iterable) A null-safe operation returning the original Iterable object if non-null or a default, empty Iterable implementation if null.static <E,T extends Iterable<E>>
TnullSafeIterable(T iterable, T defaultIterable) Returns the givenIterableif not null or empty, otherwise returns thedefaultIterable.static <T> Iterator<T>nullSafeIterator(Iterator<T> iterator) Null-safe operation returning the givenIteratorif not null or anempty Iteratorif null.static <T> List<T>nullSafeList(List<T> list) static <K,V> Map<K, V> nullSafeMap(Map<K, V> map) static <T> Set<T>nullSafeSet(Set<T> set) static longnullSafeSize(Iterable iterable) static intnullSafeSize(Collection<?> collection) Determines theCollection.size()of the givenCollection.static intnullSafeSize(Map<?, ?> map) Determines theMap.size()of the givenMap.static <T extends Comparable<T>>
List<T>Sors the elements of the givenListby their natural,Comparableordering.static <T> List<T>Returns a sub-list of elements from the givenListbased on the providedindices.static StringMethods inherited from class org.springframework.util.CollectionUtils
arrayToList, contains, contains, containsAny, containsInstance, findCommonElementType, findFirstMatch, findValueOfType, findValueOfType, firstElement, firstElement, hasUniqueObject, isEmpty, isEmpty, lastElement, lastElement, mergeArrayIntoCollection, mergePropertiesIntoMap, newHashMap, newLinkedHashMap, toArray, toIterator, toMultiValueMap, unmodifiableMultiValueMap
-
Constructor Details
-
CollectionUtils
public CollectionUtils()
-
-
Method Details
-
addAll
@NonNull public static <E,T extends Collection<E>> T addAll(@NonNull T collection, @Nullable Iterable<E> iterable) Adds all elements from the givenIterableto theCollection.- Type Parameters:
E-Classtype of the elements in theCollectionandIterable.T- concreteClasstype of theCollection.- Parameters:
collection-Collectionin which to add the elements from theIterable.iterable-Iterablecontaining the elements to add to theCollection.- Returns:
- the given
Collection. - Throws:
IllegalArgumentException- ifCollectionis null.- See Also:
-
asSet
Returns an unmodifiableSetcontaining the elements from the given object array. -
containsAny
Null-safe method to determines whether the givenCollectioncontains any elements from the given array.- Parameters:
collection-Collectionto evaluateelements- array of elements to evaluate.- Returns:
- a boolean value indicating whether the collection contains at least 1 element from the given array.
- See Also:
-
emptyIterable
Returns an emptyIterableobject. -
iterable
Adapts the given Enumeration as an Iterable object for use within a for each loop.- Type Parameters:
T- the class type of the Enumeration elements.- Parameters:
enumeration- the Enumeration to adapt as an Iterable object.- Returns:
- an Iterable instance of the Enumeration.
- See Also:
-
iterable
Adapts the given Iterator as an Iterable object for use within a for each loop. -
nullSafeCollection
Null-safe operation returning the givenCollectionif not null or an emptyCollection(implemented withList) if null.- Type Parameters:
T- Class type of theCollectionelements.- Parameters:
collection-Collectionto evaluate.- Returns:
- the given
Collectionif not null or return an emptyCollection(implemented withList). - See Also:
-
nullSafeEnumeration
Null-safe operation returning the givenEnumerationif not null or anempty Enumerationif null.- Type Parameters:
T-typeof elements contained in theEnumeration.- Parameters:
enumeration-Enumerationto evaluate.- Returns:
- the given
Enumerationif not null or anempty Enumeration. - See Also:
-
nullSafeIterable
A null-safe operation returning the original Iterable object if non-null or a default, empty Iterable implementation if null.- Type Parameters:
T- the class type of the iterable elements.- Parameters:
iterable- the Iterable object evaluated for a null reference.- Returns:
- the Iterable object if not null or a default, empty Iterable implementation otherwise.
- See Also:
-
nullSafeIterable
@Nullable public static <E,T extends Iterable<E>> T nullSafeIterable(@Nullable T iterable, @Nullable T defaultIterable) Returns the givenIterableif not null or empty, otherwise returns thedefaultIterable.- Type Parameters:
T- concreteClasstype of theIterable.E-Classtype of the elements in theIterables.- Parameters:
iterable-Iterableto evaluate.defaultIterable-Iterableto return if the giveniterableis null or empty.- Returns:
iterableif not null or empty otherwise returndefaultIterable.- See Also:
-
nullSafeIterator
Null-safe operation returning the givenIteratorif not null or anempty Iteratorif null.- Type Parameters:
T-typeof elements contained in theIterator.- Parameters:
iterator-Iteratorto evaluate.- Returns:
- the given
Iteratorif not null or anempty Iterator. - See Also:
-
nullSafeList
-
nullSafeMap
-
nullSafeSet
-
nullSafeIsEmpty
Determines whether the givenCollectionisempty.- Parameters:
collection-Collectionto evaluate.- Returns:
- a boolean value indicating whether the given
Collectionisempty. - See Also:
-
nullSafeIsEmpty
Determines whether the givenIterableis empty. -
nullSafeIsEmpty
-
nullSafeSize
Determines theCollection.size()of the givenCollection.- Parameters:
collection-Collectionto evaluate.- Returns:
- the
Collection.size()of the givenCollection. - See Also:
-
nullSafeSize
-
nullSafeSize
Determines theMap.size()of the givenMap.- Parameters:
map-Mapto evaluate.- Returns:
- the
Map.size()of the givenMap. - See Also:
-
sort
Sors the elements of the givenListby their natural,Comparableordering.- Type Parameters:
T-Comparableclass type of the collection elements.- Parameters:
list-Listof elements to sort.- Returns:
- the
Listsorted. - See Also:
-
subList
Returns a sub-list of elements from the givenListbased on the providedindices.- Type Parameters:
T- Class type of the elements in the list.- Parameters:
source-Listfrom which the elements of the sub-list is constructed.indices- array of indexes in thesourceListto the elements used to construct the sub-list.- Returns:
- a sub-list of elements from the given
Listbased on the providedindices. - Throws:
IndexOutOfBoundsException- if the array of indexes contains an index that is not within the bounds of the list.NullPointerException- if either the list or indexes are null.- See Also:
-
toString
-