Package sootup.core.util
Class StreamUtils
java.lang.Object
sootup.core.util.StreamUtils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <C> @NonNull 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.static <T> @NonNull Stream<T>iterableToStream(@NonNull Iterable<T> it) static <T> @NonNull Stream<T>iterableToStream(@NonNull Iterable<T> it, boolean parallel) static <T> @NonNull Stream<T>iteratorToStream(@NonNull Iterator<T> it) static <T> @NonNull Stream<T>iteratorToStream(@NonNull Iterator<T> it, boolean parallel) static <T> @NonNull Stream<T>optionalToStream(@NonNull Optional<T> o) static <T> @NonNull TvalueOrElse(@Nullable T value, @NonNull 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
public static <C> @NonNull 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- TheStreamto filter.clazz- The class to cast to.- Returns:
- The specified stream.
-
valueOrElse
public static <T> @NonNull T valueOrElse(@Nullable T value, @NonNull T other) 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:
-