Class BaseStreamEx<T,​S extends java.util.stream.BaseStream<T,​S>,​SPLTR extends java.util.Spliterator<T>,​B extends BaseStreamEx<T,​S,​SPLTR,​B>>

  • All Implemented Interfaces:
    java.lang.AutoCloseable, java.util.stream.BaseStream<T,​S>
    Direct Known Subclasses:
    AbstractStreamEx, DoubleStreamEx, IntStreamEx, LongStreamEx

    abstract class BaseStreamEx<T,​S extends java.util.stream.BaseStream<T,​S>,​SPLTR extends java.util.Spliterator<T>,​B extends BaseStreamEx<T,​S,​SPLTR,​B>>
    extends java.lang.Object
    implements java.util.stream.BaseStream<T,​S>
    • Field Detail

      • stream

        private S extends java.util.stream.BaseStream<T,​S> stream
      • spliterator

        SPLTR extends java.util.Spliterator<T> spliterator
    • Method Detail

      • createStream

        abstract S createStream()
      • stream

        final S stream()
      • spliterator

        public SPLTR spliterator()
        Specified by:
        spliterator in interface java.util.stream.BaseStream<T,​S extends java.util.stream.BaseStream<T,​S>>
      • isParallel

        public boolean isParallel()
        Specified by:
        isParallel in interface java.util.stream.BaseStream<T,​S extends java.util.stream.BaseStream<T,​S>>
      • sequential

        public S sequential()
        Specified by:
        sequential in interface java.util.stream.BaseStream<T,​S extends java.util.stream.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 java.util.stream.BaseStream<T,​S extends java.util.stream.BaseStream<T,​S>>
      • parallel

        public S parallel​(java.util.concurrent.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 java.util.stream.BaseStream<T,​S extends java.util.stream.BaseStream<T,​S>>
      • onClose

        public S onClose​(java.lang.Runnable closeHandler)
        Specified by:
        onClose in interface java.util.stream.BaseStream<T,​S extends java.util.stream.BaseStream<T,​S>>
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.util.stream.BaseStream<T,​S extends java.util.stream.BaseStream<T,​S>>
      • chain

        public abstract <U> U chain​(java.util.function.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