Class MoreStreams

java.lang.Object
com.atlassian.bitbucket.util.MoreStreams

public class MoreStreams extends Object
Additional utilities for creating streams.
  • Method Details

    • asIterable

      @Nonnull public static <T> Iterable<T> asIterable(@Nonnull Stream<T> stream)
      Returns the Stream as an Iterable.

      Note: the returned Iterable can only be iterated once.

      Type Parameters:
      T - the type of element in the stream
      Parameters:
      stream - the stream
      Returns:
      the Stream as an Iterable
      Since:
      4.12
    • streamEnumeration

      @Nonnull public static <T> Stream<T> streamEnumeration(@Nonnull Enumeration<T> enumeration)
      Converts an Enumeration to a Stream.
      Type Parameters:
      T - the type of element in the Enumeration
      Parameters:
      enumeration - the Enumeration to stream
      Returns:
      a Stream over the provided enumeration
      Throws:
      NullPointerException - if the provided enumeration is null
      Since:
      4.9
    • streamIterable

      @Nonnull public static <T> Stream<T> streamIterable(@Nonnull Iterable<T> iterable)
      Converts an Iterable to a Stream.
      Type Parameters:
      T - the type of element in the Iterable
      Parameters:
      iterable - the Iterable to stream
      Returns:
      a Stream over the provided iterable
      Throws:
      NullPointerException - if the provided iterable is null
    • streamOptional

      @Nonnull public static <T> Stream<T> streamOptional(@Nonnull Optional<T> optional)
      Converts an Optional to a single-element or empty Stream.
      Type Parameters:
      T - the type of element in the Optional
      Parameters:
      optional - the Optional to stream
      Returns:
      a single-element Stream if the Optional is present; otherwise an empty Stream
      Throws:
      NullPointerException - if the provided optional is null