Class ForkJoinStream


  • public class ForkJoinStream
    extends Object
    This class can be used to process a Stream in parallel using a custom ForkJoinPool.
    Author:
    Vasilis Vryniotis
    • Constructor Detail

      • ForkJoinStream

        public ForkJoinStream​(ConcurrencyConfiguration concurrencyConfiguration)
        Default constructor which receives the Concurrency Configuration object.
        Parameters:
        concurrencyConfiguration -
    • Method Detail

      • forEach

        public <T> void forEach​(Stream<T> stream,
                                Consumer<? super T> action)
        Executes forEach on the provided stream. If the Stream is parallel, it is executed using the custom pool, else it is executed directly from the main thread.
        Type Parameters:
        T -
        Parameters:
        stream -
        action -
      • map

        public <T,​R> Stream<R> map​(Stream<T> stream,
                                         Function<? super T,​? extends R> mapper)
        Executes map on the provided stream. If the Stream is parallel, it is executed using the custom pool, else it is executed directly from the main thread.
        Type Parameters:
        T -
        R -
        Parameters:
        stream -
        mapper -
        Returns:
      • collect

        public <T,​R,​A> R collect​(Stream<T> stream,
                                             Collector<? super T,​A,​R> collector)
        Executes collect on the provided stream using the provided collector. If the Stream is parallel, it is executed using the custom pool, else it is executed directly from the main thread.
        Type Parameters:
        T -
        R -
        A -
        Parameters:
        stream -
        collector -
        Returns:
      • min

        public <T> Optional<T> min​(Stream<T> stream,
                                   Comparator<? super T> comparator)
        Executes min on the provided stream using the provided collector. If the Stream is parallel, it is executed using the custom pool, else it is executed directly from the main thread.
        Type Parameters:
        T -
        Parameters:
        stream -
        comparator -
        Returns:
      • max

        public <T> Optional<T> max​(Stream<T> stream,
                                   Comparator<? super T> comparator)
        Executes max on the provided stream using the provided collector. If the Stream is parallel, it is executed using the custom pool, else it is executed directly from the main thread.
        Type Parameters:
        T -
        Parameters:
        stream -
        comparator -
        Returns:
      • sum

        public double sum​(DoubleStream stream)
        Executes sum on the provided DoubleStream using the provided collector. If the Stream is parallel, it is executed using the custom pool, else it is executed directly from the main thread.
        Parameters:
        stream -
        Returns: