public abstract class CollectionUtils extends CollectionUtils
Collection
,
Collections
,
Enumeration
,
Iterator
,
List
,
Map
,
Set
,
CollectionUtils
Constructor and Description |
---|
CollectionUtils() |
Modifier and Type | Method and Description |
---|---|
static <E,T extends Collection<E>> |
addAll(T collection,
Iterable<E> iterable)
Adds all elements from the given
Iterable to the Collection . |
static <T> Set<T> |
asSet(T... elements)
Returns an unmodifiable
Set containing the elements from the given object array. |
static boolean |
containsAny(Collection<?> collection,
Object... elements)
Null-safe method to determines whether the given
Collection contains any elements from the given array. |
static <E,T extends Iterable<E>> |
defaultIfEmpty(T iterable,
T defaultIterable)
Returns the given
Iterable if not null or empty, otherwise returns the defaultIterable . |
static <T> Iterable<T> |
emptyIterable()
Returns an empty
Iterable object. |
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> |
iterable(Iterator<T> iterator)
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 given
Collection if not null
or an empty Collection (implemented with List ) if null. |
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 <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 <T extends Comparable<T>> |
sort(List<T> list)
Sors the elements of the given
List by their natural, Comparable ordering. |
static <T> List<T> |
subList(List<T> source,
int... indices)
Returns a sub-list of elements from the given
List based on the provided indices . |
static String |
toString(Map<?,?> map) |
arrayToList, contains, contains, containsAny, containsInstance, findCommonElementType, findFirstMatch, findValueOfType, findValueOfType, hasUniqueObject, isEmpty, isEmpty, mergeArrayIntoCollection, mergePropertiesIntoMap, toArray, toIterator, toMultiValueMap, unmodifiableMultiValueMap
public static <E,T extends Collection<E>> T addAll(T collection, Iterable<E> iterable)
Iterable
to the Collection
.E
- Class
type of the elements in the Collection
and Iterable
.T
- concrete Class
type of the Collection
.collection
- Collection
in which to add the elements from the Iterable
.iterable
- Iterable
containing the elements to add to the Collection
.Collection
.IllegalArgumentException
- if Collection
is null.Iterable
,
Collection
@SafeVarargs public static <T> Set<T> asSet(T... elements)
Set
containing the elements from the given object array.public static boolean containsAny(Collection<?> collection, Object... elements)
Collection
contains any elements from the given array.collection
- Collection
to evaluateelements
- array of elements to evaluate.Collection.contains(Object)
public static <E,T extends Iterable<E>> T defaultIfEmpty(T iterable, T defaultIterable)
Iterable
if not null or empty, otherwise returns the defaultIterable
.T
- concrete Class
type of the Iterable
.E
- Class
type of the elements in the Iterables
.iterable
- Iterable
to evaluate.defaultIterable
- Iterable
to return if the given iterable
is null or empty.iterable
if not null or empty otherwise return defaultIterable
.Iterable
public static <T> Iterable<T> emptyIterable()
Iterable
object.T
- Class
type of the elements in the Iterable
.Iterable
.Iterable
,
nullSafeIterable(Iterable)
public static <T> Iterable<T> iterable(Enumeration<T> enumeration)
T
- the class type of the Enumeration elements.enumeration
- the Enumeration to adapt as an Iterable object.Iterable
,
Enumeration
public static <T> Iterable<T> iterable(Iterator<T> iterator)
public static <T> Collection<T> nullSafeCollection(Collection<T> collection)
Collection
if not null
or an empty Collection
(implemented with List
) if null.T
- Class type of the Collection
elements.collection
- Collection
to evaluate.Collection
if not null or return an empty Collection
(implemented with List
).Collections.emptyList()
,
Collection
public static <T> Iterable<T> nullSafeIterable(Iterable<T> iterable)
public static <T extends Comparable<T>> List<T> sort(List<T> list)
List
by their natural, Comparable
ordering.T
- Comparable
class type of the collection elements.list
- List
of elements to sort.List
sorted.Collections.sort(List)
,
List
public static <T> List<T> subList(List<T> source, int... indices)
List
based on the provided indices
.T
- Class type of the elements in the list.source
- List
from which the elements of the sub-list is constructed.indices
- array of indexes in the source
List
to the elements
used to construct the sub-list.List
based on the provided indices
.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.List
Copyright © 2011–2017 Pivotal Software, Inc.. All rights reserved.