Package org.kiwiproject.collect
Class KiwiStreams
- java.lang.Object
-
- org.kiwiproject.collect.KiwiStreams
-
-
Constructor Summary
Constructors Constructor Description KiwiStreams()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> Optional<T>
findFirst(Stream<?> stream, Class<T> typeToFind)
Find the first object having the giventypeToFind
in a stream of objects.static <T> Optional<T>
findFirst(Stream<?> stream, Class<T> typeToFind, Predicate<T> predicate)
Find the first object having the giventypeToFind
and matching the supplied predicate in a stream of objects.
-
-
-
Method Detail
-
findFirst
public static <T> Optional<T> findFirst(Stream<?> stream, Class<T> typeToFind)
Find the first object having the giventypeToFind
in a stream of objects.- Type Parameters:
T
- the type token of the type we want to find- Parameters:
stream
- the stream of objects of some (unknown) typetypeToFind
- the class of the object to find- Returns:
- an Optional containing the first object of the given type, or empty
-
findFirst
public static <T> Optional<T> findFirst(Stream<?> stream, Class<T> typeToFind, Predicate<T> predicate)
Find the first object having the giventypeToFind
and matching the supplied predicate in a stream of objects.- Type Parameters:
T
- the type token of the type we want to find- Parameters:
stream
- the stream of objects of some (unknown) typetypeToFind
- the class of the object to findpredicate
- the condition that must be satisfied for a match to occur- Returns:
- an Optional containing the first object of the given type, or empty
-
-