Package org.eclipse.cdt.core.parser.util
Class CollectionUtils
java.lang.Object
org.eclipse.cdt.core.parser.util.CollectionUtils
Useful utility methods for dealing with Collections.
- Restriction:
- This class is not intended to be instantiated by clients.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <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> 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<U> corresponding to a T in a Map<T, List<U>>.static <T,
U extends Collection<T>>
Umerge
(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.
-
Method Details
-
reverseIterator
Returns an iterator that iterates backwards over the given list. The remove() method is not implemented and will throw UnsupportedOperationException. The returned iterator does not support the remove() method.- Throws:
NullPointerException
- if list isnull
-
reverseIterable
Allows a foreach loop to iterate backwards over a list from the end to the start.Example use:
for (Object o : reverseIterable(list)) { ... }
- Throws:
NullPointerException
- if list is null
-
iterable
Creates an Iterable instance that just returns the given Iterator from its iterator() method. This is useful for using an iterator in a foreach loop directly.Example use:
for (Object o : iterable(iterator)) { ... }
- Throws:
NullPointerException
- if list isnull
-
findFirstAndRemove
Finds the first object in the heterogeneous list that is an instance of the given class, removes it from the list, and returns it. If there is not object in the list of the given type the list is left unmodified and null is returned.- Throws:
NullPointerException
- if list or clazz is nullUnsupportedOperationException
- if the list's Iterator does not support the remove() method
-
merge
Combines two collections into one.- Parameters:
c1
- The first collection. May be modified as a result of the call. May benull
.c2
- The second collection. May benull
.- Returns:
- A collection containing elements from both input collections,
or
null
if both,c1
andc2
arenull
. - Since:
- 5.4
-
listMapGet
Returns a List<U> corresponding to a T in a Map<T, List<U>>. If the mapping doesn't exist, creates it with an empty list as the initial value.- Since:
- 5.6
-
filter
Filter the elements of a collection down to just the ones that match the given predicate.- Since:
- 5.6
-