Class ParallelStreamSupport<T>

    • Method Detail

      • parallelStream

        public static <T> Stream<T> parallelStream​(Collection<T> collection,
                                                   ForkJoinPool workerPool)
        Creates a parallel stream from the given Collection. This operation is similar to Collection.parallelStream() with the difference that a parallel terminal operation will be executed in the given ForkJoinPool.
        Type Parameters:
        T - The type of stream elements.
        Parameters:
        collection - Collection to create the parallel stream from. Must not be null.
        workerPool - Thread pool for parallel execution of a terminal operation. Must not be null.
        Returns:
        A parallel stream that executes a terminal operation in the given ForkJoinPool.
        See Also:
        Collection.parallelStream()
      • parallelStream

        public static <T> Stream<T> parallelStream​(T[] array,
                                                   ForkJoinPool workerPool)
        Creates a parallel stream from the given Array. This operation is similar to calling Arrays.stream(array).parallel() with the difference that a parallel terminal operation will be executed in the given ForkJoinPool.
        Type Parameters:
        T - The type of stream elements.
        Parameters:
        array - Array to create the parallel stream from. Must not be null.
        workerPool - Thread pool for parallel execution of a terminal operation. Must not be null.
        Returns:
        A parallel stream that executes a terminal operation in the given ForkJoinPool.
        See Also:
        Arrays.stream(Object[])
      • parallelStream

        public static <T> Stream<T> parallelStream​(Spliterator<T> spliterator,
                                                   ForkJoinPool workerPool)
        Creates a parallel stream from the given Spliterator. This operation is similar to calling StreamSupport.stream(spliterator, true) with the difference that a parallel terminal operation will be executed in the given ForkJoinPool.
        Type Parameters:
        T - The type of stream elements.
        Parameters:
        spliterator - A Spliterator describing the stream elements. Must not be null.
        workerPool - Thread pool for parallel execution of a terminal operation. Must not be null.
        Returns:
        A parallel stream that executes a terminal operation in the given ForkJoinPool.
        See Also:
        StreamSupport.stream(Spliterator, boolean)
      • parallelStream

        public static <T> Stream<T> parallelStream​(Supplier<? extends Spliterator<T>> supplier,
                                                   int characteristics,
                                                   ForkJoinPool workerPool)
        Creates a parallel stream from the given Spliterator supplier. This operation is similar to calling StreamSupport.stream(supplier, characteristics, true) with the difference that a parallel terminal operation will be executed in the given ForkJoinPool.
        Type Parameters:
        T - The type of stream elements.
        Parameters:
        supplier - A Supplier of a Spliterator. Must not be null.
        characteristics - Spliterator characteristics of the supplied Spliterator. The characteristics must be equal to supplier.get().characteristics(), otherwise undefined behavior may occur when terminal operation commences.
        workerPool - Thread pool for parallel execution of a terminal operation. Must not be null.
        Returns:
        A parallel stream that executes a terminal operation in the given ForkJoinPool.
        See Also:
        StreamSupport.stream(Supplier, int, boolean)
      • parallelStream

        public static <T> Stream<T> parallelStream​(Stream.Builder<T> builder,
                                                   ForkJoinPool workerPool)
        Creates a parallel stream from the given Stream.Builder. This operation is similar to calling builder.build().parallel() with the difference that a parallel terminal operation will be executed in the given ForkJoinPool.
        Type Parameters:
        T - The type of stream elements.
        Parameters:
        builder - The builder to create the stream from. Must not be null.
        workerPool - Thread pool for parallel execution of a terminal operation. Must not be null.
        Returns:
        A parallel stream that executes a terminal operation in the given ForkJoinPool.
        See Also:
        Stream.builder()
      • iterate

        public static <T> Stream<T> iterate​(T seed,
                                            UnaryOperator<T> operator,
                                            ForkJoinPool workerPool)
        Creates a parallel infinite ordered stream produced by iterative application of a function f to an initial element seed. This operation is similar to calling Stream.iterate(seed, operator).parallel() with the difference that a parallel terminal operation will be executed in the given ForkJoinPool.
        Type Parameters:
        T - The type of stream elements.
        Parameters:
        seed - The initial element.
        operator - A function to be applied to to the previous element to produce a new element. Must not be null.
        workerPool - Thread pool for parallel execution of a terminal operation. Must not be null.
        Returns:
        A parallel stream that executes a terminal operation in the given ForkJoinPool.
        See Also:
        Stream.iterate(Object, UnaryOperator)
      • generate

        public static <T> Stream<T> generate​(Supplier<T> supplier,
                                             ForkJoinPool workerPool)
        Creates a parallel infinite sequential unordered stream where each element is generated by the provided Supplier. This operation is similar to calling Stream.generate(supplier).parallel() with the difference that a parallel terminal operation will be executed in the given ForkJoinPool.
        Type Parameters:
        T - The type of stream elements.
        Parameters:
        supplier - The Supplier of generated elements. Must not be null.
        workerPool - Thread pool for parallel execution of a terminal operation. Must not be null.
        Returns:
        A parallel stream that executes a terminal operation in the given ForkJoinPool.
        See Also:
        Stream.generate(Supplier)
      • concat

        public static <T> Stream<T> concat​(Stream<? extends T> a,
                                           Stream<? extends T> b,
                                           ForkJoinPool workerPool)
        Creates a lazily concatenated parallel stream whose elements are all the elements of the first stream followed by all the elements of the second stream. This operation is similar to calling Stream.concat(a, b).parallel() with the difference that a parallel terminal operation will be executed in the given ForkJoinPool.
        Type Parameters:
        T - The type of stream elements.
        Parameters:
        a - The first stream. Must not be null.
        b - The second stream. Must not be null.
        workerPool - Thread pool for parallel execution of a terminal operation. Must not be null.
        Returns:
        A parallel stream that executes a terminal operation in the given ForkJoinPool.
        See Also:
        Stream.concat(Stream, Stream)
      • limit

        public Stream<T> limit​(long maxSize)
        Specified by:
        limit in interface Stream<T>
      • collect

        public <R,​A> R collect​(Collector<? super T,​A,​R> collector)
        Specified by:
        collect in interface Stream<T>
      • count

        public long count()
        Specified by:
        count in interface Stream<T>
      • execute

        protected void execute​(Runnable terminalOperation)
      • execute

        protected <R> R execute​(Callable<R> terminalOperation)