Class StreamUtils

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

public class StreamUtils extends Object
  • Constructor Details

    • StreamUtils

      public StreamUtils()
  • Method Details

    • optionalToStream

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

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

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

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

      @Nonnull public static <T> Stream<T> iteratorToStream(@Nonnull Iterator<T> it, boolean parallel)
      Converts an Iterator to a Stream.
    • 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 - The Stream to filter.
      clazz - The class to cast to.
      Returns:
      The specified stream.
    • valueOrElse

      @Nonnull public static <T> 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: