Package org.esa.snap.core.util
Class CollectionHelper
- java.lang.Object
-
- org.esa.snap.core.util.CollectionHelper
-
public final class CollectionHelper extends Object
Helper class for simplifying lambda expression usage on collections and arrays.
-
-
Constructor Summary
Constructors Constructor Description CollectionHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> T
firstOrDefault(Collection<T> collection, Predicate<T> condition)
Returns the first element of the collection that satisfies the given condition, ornull
if no such element exists.static <T> T
firstOrDefault(T[] array, Predicate<T> condition)
Returns the first element of the array that satisfies the given condition, ornull
if no such element exists.static <T> List<T>
where(Collection<T> collection, Predicate<T> filter)
Selects the list of collection elements that satisfy the given filter.static <T> List<T>
where(T[] array, Predicate<T> filter)
Selects the list of array elements that satisfy the given filter.
-
-
-
Method Detail
-
firstOrDefault
public static <T> T firstOrDefault(Collection<T> collection, Predicate<T> condition)
Returns the first element of the collection that satisfies the given condition, ornull
if no such element exists. If the condition isnull
, the first element of the collection is returned.- Type Parameters:
T
- The type of the collection elements- Parameters:
collection
- The collection to be searchedcondition
- The condition to be applied- Returns:
- The first element of the collection matching the condition, or
null
-
firstOrDefault
public static <T> T firstOrDefault(T[] array, Predicate<T> condition)
Returns the first element of the array that satisfies the given condition, ornull
if no such element exists. If the condition isnull
, the first element of the array is returned.- Type Parameters:
T
- The type of the array elements- Parameters:
array
- The array to be searchedcondition
- The condition to be applied- Returns:
- The first element of the array matching the condition, or
null
-
where
public static <T> List<T> where(Collection<T> collection, Predicate<T> filter)
Selects the list of collection elements that satisfy the given filter. If the filter isnull
, all the collection elements are returned.- Type Parameters:
T
- The type of collection elements- Parameters:
collection
- The collection to be filteredfilter
- The filter to be applied- Returns:
- A list of elements satisfying the filter
-
where
public static <T> List<T> where(T[] array, Predicate<T> filter)
Selects the list of array elements that satisfy the given filter. If the filter isnull
, all the array elements are returned.- Type Parameters:
T
- The type of array elements- Parameters:
array
- The array to be filteredfilter
- The filter to be applied- Returns:
- A list of elements satisfying the filter
-
-