Package sootup.core.util
Class StreamUtils
java.lang.Object
sootup.core.util.StreamUtils
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <C> Stream<C>
filterAllCasted
(Stream<?> stream, Class<C> clazz) Filters and converts all objects from a stream that are instances of the specified class.static <T> Stream<T>
iterableToStream
(Iterable<T> it) static <T> Stream<T>
iterableToStream
(Iterable<T> it, boolean parallel) static <T> Stream<T>
iteratorToStream
(Iterator<T> it) static <T> Stream<T>
iteratorToStream
(Iterator<T> it, boolean parallel) static <T> Stream<T>
optionalToStream
(Optional<T> o) static <T> T
valueOrElse
(T value, T other) Returns the value, if it is notnull
; otherwise, it returns other.
-
Constructor Details
-
StreamUtils
public StreamUtils()
-
-
Method Details
-
optionalToStream
-
iterableToStream
-
iterableToStream
-
iteratorToStream
-
iteratorToStream
-
filterAllCasted
@Nonnull public static <C> Stream<C> filterAllCasted(@Nonnull Stream<?> stream, @Nonnull Class<C> clazz) Filters and converts all objects from a stream that are instances of the specified class.Example:
List<Foo> foosWithName = filterAllCasted(collection.stream(), Foo.class) .filter(it -> !it.getName().isEmpty());
- Type Parameters:
C
- The type of the casted object.- Parameters:
stream
- TheStream
to filter.clazz
- The class to cast to.- Returns:
- The specified stream.
-
valueOrElse
Returns the value, if it is notnull
; otherwise, it returns other.- Type Parameters:
T
- The type of the value.- Parameters:
value
- The value to get, if it is notnull
.other
- The other to get, if value isnull
.- Returns:
- value, if it is not
null
; otherwise, other. - See Also:
-