Class StreamPipes

java.lang.Object
io.inverno.mod.irt.StreamPipes

public final class StreamPipes extends Object

A collection of pipes used to transform streams including: filter, sort, map, flatMap...

Since:
1.2
Author:
Jeremy Kuhn
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> StreamPipe<T,T>
    Returns a pipe which converts a stream to filter out duplicates.
    static <T, U> StreamPipe<T,T>
    filter(Function<? super T,? extends U> keySelector, Predicate<? super U> predicate)
    Returns a pipe which converts a stream to filter out elements based on their keys computed using the specified key selector that do not pass the specified predicate test.
    static <T> StreamPipe<T,T>
    filter(Predicate<? super T> predicate)
    Returns a pipe which converts a stream to filter out elements that do not pass the specified predicate test.
    static <T, R> StreamPipe<T,R>
    flatMap(Function<? super T,? extends Stream<? extends R>> mapper)
    Returns a pipe which transforms the elements of the stream into streams by applying the specified mapper function, then flatten these inner stream into a single stream sequentially using concatenation.
    static <T, R> StreamPipe<T,R>
    map(Function<? super T,? extends R> mapper)
    Returns a pipe which transforms the elements of a stream by applying the specified mapper function.
    static <T> StreamPipe<T,T>
    Returns a pipe which converts a stream to sort the elements in natural order.
    static <T> StreamPipe<T,T>
    sort(Comparator<? super T> comparator)
    Returns a pipe which converts a stream to sort the elements using the specified comparator.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • StreamPipes

      public StreamPipes()
  • Method Details

    • distinct

      public static <T> StreamPipe<T,T> distinct()

      Returns a pipe which converts a stream to filter out duplicates.

      Type Parameters:
      T - the type of element in the stream
      Returns:
      a stream pipe
    • sort

      public static <T> StreamPipe<T,T> sort()

      Returns a pipe which converts a stream to sort the elements in natural order.

      Type Parameters:
      T - the type of element in the stream
      Returns:
      a stream pipe
    • sort

      public static <T> StreamPipe<T,T> sort(Comparator<? super T> comparator)

      Returns a pipe which converts a stream to sort the elements using the specified comparator.

      Type Parameters:
      T - the type of element in the stream
      Parameters:
      comparator - a comparator
      Returns:
      a stream pipe
    • filter

      public static <T> StreamPipe<T,T> filter(Predicate<? super T> predicate)

      Returns a pipe which converts a stream to filter out elements that do not pass the specified predicate test.

      Type Parameters:
      T - the type of element in the stream
      Parameters:
      predicate - a predicate
      Returns:
      a stream pipe
    • filter

      public static <T, U> StreamPipe<T,T> filter(Function<? super T,? extends U> keySelector, Predicate<? super U> predicate)

      Returns a pipe which converts a stream to filter out elements based on their keys computed using the specified key selector that do not pass the specified predicate test.

      Type Parameters:
      T - the type of element in the stream
      U - the type of the computed keys
      Parameters:
      keySelector - a key selector
      predicate - a predicate
      Returns:
      a stream pipe
    • map

      public static <T, R> StreamPipe<T,R> map(Function<? super T,? extends R> mapper)

      Returns a pipe which transforms the elements of a stream by applying the specified mapper function.

      Type Parameters:
      T - the type of element in the stream
      R - the type of element in the resulting stream
      Parameters:
      mapper - a mapper function
      Returns:
      a stream pipe
    • flatMap

      public static <T, R> StreamPipe<T,R> flatMap(Function<? super T,? extends Stream<? extends R>> mapper)

      Returns a pipe which transforms the elements of the stream into streams by applying the specified mapper function, then flatten these inner stream into a single stream sequentially using concatenation.

      Type Parameters:
      T - the type of element in the publisher
      R - the type of element in the resulting publisher
      Parameters:
      mapper - a mapper function
      Returns:
      a stream pipe