Class BaseStreamEx<T,S extends BaseStream<T,S>,SPLTR extends Spliterator<T>,B extends BaseStreamEx<T,S,SPLTR,B>>

java.lang.Object
one.util.streamex.BaseStreamEx<T,S,SPLTR,B>
All Implemented Interfaces:
AutoCloseable, BaseStream<T,S>
Direct Known Subclasses:
AbstractStreamEx, DoubleStreamEx, IntStreamEx, LongStreamEx

abstract class BaseStreamEx<T,S extends BaseStream<T,S>,SPLTR extends Spliterator<T>,B extends BaseStreamEx<T,S,SPLTR,B>> extends Object implements BaseStream<T,S>
  • Field Details

  • Constructor Details

  • Method Details

    • createStream

      abstract S createStream()
    • stream

      final S stream()
    • spliterator

      public SPLTR spliterator()
      Specified by:
      spliterator in interface BaseStream<T,S extends BaseStream<T,S>>
    • isParallel

      public boolean isParallel()
      Specified by:
      isParallel in interface BaseStream<T,S extends BaseStream<T,S>>
    • sequential

      public S sequential()
      Specified by:
      sequential in interface BaseStream<T,S extends BaseStream<T,S>>
    • parallel

      public S parallel()

      If this stream was created using parallel(ForkJoinPool), the new stream forgets about supplied custom ForkJoinPool and its terminal operation will be executed in common pool.

      Specified by:
      parallel in interface BaseStream<T,S extends BaseStream<T,S>>
    • parallel

      public S parallel(ForkJoinPool fjp)
      Returns an equivalent stream that is parallel and bound to the supplied ForkJoinPool.

      This is an intermediate operation.

      The terminal operation of this stream or any derived stream (except the streams created via parallel() or sequential() methods) will be executed inside the supplied ForkJoinPool. If current thread does not belong to that pool, it will wait till calculation finishes.

      Parameters:
      fjp - a ForkJoinPool to submit the stream operation to.
      Returns:
      a parallel stream bound to the supplied ForkJoinPool
      Since:
      0.2.0
    • unordered

      public S unordered()
      Specified by:
      unordered in interface BaseStream<T,S extends BaseStream<T,S>>
    • onClose

      public S onClose(Runnable closeHandler)
      Specified by:
      onClose in interface BaseStream<T,S extends BaseStream<T,S>>
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface BaseStream<T,S extends BaseStream<T,S>>
    • chain

      public abstract <U> U chain(Function<? super B,U> mapper)
      Applies the supplied function to this stream and returns the result of the function.

      This method can be used to add more functionality in the fluent style. For example, consider user-defined static method batches(stream, n) which breaks the stream into batches of given length. Normally you would write batches(StreamEx.of(input).map(...), 10).filter(...). Using the chain() method you can write in more fluent manner: StreamEx.of(input).map(...).chain(s -> batches(s, 10)).filter(...).

      You could even go further and define a method which returns a function like <T> UnaryOperator<StreamEx<T>> batches(int n) and use it like this: StreamEx.of(input).map(...).chain(batches(10)).filter(...).

      Type Parameters:
      U - the type of the function result.
      Parameters:
      mapper - function to invoke.
      Returns:
      the result of the function invocation.
      Since:
      0.5.4