Class StreamHelper

java.lang.Object
io.github.torand.javacommons.stream.StreamHelper

public final class StreamHelper extends Object
Helper functions for streams
  • Method Details

    • streamSafely

      public static <T> Stream<T> streamSafely(Iterable<T> iterable)
      Creates a stream from the elements in the specified iterable. If the iterable is null or contains no elements, an empty stream is returned.
      Type Parameters:
      T - the element type.
      Parameters:
      iterable - the iterable.
      Returns:
      the stream.
    • streamSafely

      public static <T> Stream<T> streamSafely(Iterator<T> iterator)
      Creates a stream from the elements in the specified iterator. If the iterator is null or contains no elements, an empty stream is returned.
      Type Parameters:
      T - the element type.
      Parameters:
      iterator - the iterator.
      Returns:
      the stream.
    • streamSafely

      @SafeVarargs public static <T> Stream<T> streamSafely(T... items)
      Creates a stream from the elements in the specified array. If the array is null or contains no elements, an empty stream is returned.
      Type Parameters:
      T - the item type.
      Parameters:
      items - the items.
      Returns:
      the stream.
    • concatAndStream

      public static <T> Stream<T> concatAndStream(Iterable<T> first, Iterable<T> second)
      Creates a concatenated stream from the elements in the specified iterables.
      Type Parameters:
      T - the element type.
      Parameters:
      first - the first iterable.
      second - the second iterable.
      Returns:
      the stream.
    • concatStreams

      public static <T> Stream<T> concatStreams(Stream<T>... streams)
      Concatenates an arbitrary number of streams.
      Type Parameters:
      T - the stream value type.
      Parameters:
      streams - the streams to concatenate.
      Returns:
      the concatenates streams.
    • toReversedList

      public static <T> Collector<T,?,List<T>> toReversedList()
      Returns a Collector producing a list with elements in reversed order.
      Type Parameters:
      T - the value type.
      Returns:
      the Collector object.