Class StreamUtils

java.lang.Object
sootup.core.util.StreamUtils

public class StreamUtils extends Object
  • Constructor Details

    • StreamUtils

      public StreamUtils()
  • Method Details

    • optionalToStream

      public static <T> @NonNull Stream<T> optionalToStream(@NonNull Optional<T> o)
      Converts an Optional to a Stream.
    • iterableToStream

      public static <T> @NonNull Stream<T> iterableToStream(@NonNull Iterable<T> it)
      Converts an Iterable to a Stream.
    • iterableToStream

      public static <T> @NonNull Stream<T> iterableToStream(@NonNull Iterable<T> it, boolean parallel)
      Converts an Iterable to a Stream.
    • iteratorToStream

      public static <T> @NonNull Stream<T> iteratorToStream(@NonNull Iterator<T> it)
      Converts an Iterator to a Stream.
    • iteratorToStream

      public static <T> @NonNull Stream<T> iteratorToStream(@NonNull Iterator<T> it, boolean parallel)
      Converts an Iterator to a Stream.
    • 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 - The Stream to 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 not null; otherwise, it returns other.
      Type Parameters:
      T - The type of the value.
      Parameters:
      value - The value to get, if it is not null.
      other - The other to get, if value is null.
      Returns:
      value, if it is not null; otherwise, other.
      See Also: