Commit faff24d3 authored by Alexander Diewald's avatar Alexander Diewald
Browse files

Common: LambdaUtils: Add firstOfType util method.

The firstOfType method returns the first element from
a given collection that is assignable from the given
type. This method allows to reduce the LoCs since the
described task is quite common.
refs 3203
parent 4e0e9ebd
......@@ -237,6 +237,20 @@ public class LambdaUtils {
return outCol;
}
/**
* Returns the first element of the given {@code inCol} collection that is assignable from the
* given type.
*
* @param inCol
* Collection to be filtered.
* @param typeFilter
* Type for which the elements shall be filtered.
* @return Optional of the first found element of the given type.
*/
public static <S, T> Optional<T> firstOfType(Collection<S> inCol, Class<T> typeFilter) {
return getFirst(filterType(inCol, typeFilter));
}
/**
* Applies the given {@code action} to each element of the given {@code inputCollection}.
*
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment