public final class CollectionUtils extends Object
Modifier and Type | Method and Description |
---|---|
static <T> Collection<T> |
filter(Collection<T> collection,
IUnaryPredicate<T> predicate)
Filter the elements of a collection down to just the ones that match the given predicate.
|
static <T> T |
findFirstAndRemove(List<?> list,
Class<T> clazz)
Finds the first object in the heterogeneous list that is an instance of
the given class, removes it from the list, and returns it.
|
static <T> Iterable<T> |
iterable(Iterator<T> iter)
Creates an Iterable instance that just returns the given Iterator from its iterator() method.
|
static <T,U> List<U> |
listMapGet(Map<T,List<U>> m,
T t)
Returns a List corresponding to a T in a Map
|
static <T,U extends Collection<T>> |
merge(U c1,
U c2)
Combines two collections into one.
|
static <T> Iterable<T> |
reverseIterable(List<T> list)
Allows a foreach loop to iterate backwards over a list from the end to the start.
|
static <T> Iterator<T> |
reverseIterator(List<T> list)
Returns an iterator that iterates backwards over the given list.
|
public static <T> Iterator<T> reverseIterator(List<T> list)
NullPointerException
- if list is null
public static <T> Iterable<T> reverseIterable(List<T> list)
Example use:
for (Object o : reverseIterable(list)) { ... }
NullPointerException
- if list is nullpublic static <T> Iterable<T> iterable(Iterator<T> iter)
Example use:
for (Object o : iterable(iterator)) { ... }
NullPointerException
- if list is null
public static <T> T findFirstAndRemove(List<?> list, Class<T> clazz)
NullPointerException
- if list or clazz is nullUnsupportedOperationException
- if the list's Iterator does not support the remove()
methodpublic static <T,U extends Collection<T>> U merge(U c1, U c2)
c1
- The first collection. May be modified as a result of the call. May be null
.c2
- The second collection. May be null
.null
if both, c1
and c2
are null
.public static <T,U> List<U> listMapGet(Map<T,List<U>> m, T t)
public static <T> Collection<T> filter(Collection<T> collection, IUnaryPredicate<T> predicate)
Copyright (c) IBM Corp. and others 2004, 2020. All Rights Reserved.