Package org.esa.snap.core.util
Class CollectionHelper
java.lang.Object
org.esa.snap.core.util.CollectionHelper
Helper class for simplifying lambda expression usage on collections and arrays.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TfirstOrDefault(Collection<T> collection, Predicate<T> condition) Returns the first element of the collection that satisfies the given condition, ornullif no such element exists.static <T> TfirstOrDefault(T[] array, Predicate<T> condition) Returns the first element of the array that satisfies the given condition, ornullif 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> Selects the list of array elements that satisfy the given filter.
-
Constructor Details
-
CollectionHelper
public CollectionHelper()
-
-
Method Details
-
firstOrDefault
Returns the first element of the collection that satisfies the given condition, ornullif 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
Returns the first element of the array that satisfies the given condition, ornullif 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
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
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
-