Class CollectionRunner<E>

java.lang.Object
uk.ac.starlink.table.join.CollectionRunner<E>

public class CollectionRunner<E> extends Object
Harnesses a SplitProcessor to perform parallel processing on elements of a Java Collection.

This more or less duplicates part of the behaviour of the Java 8 streams framework, but it provides the additional control available from SplitProcessor, and also works with a ProgressIndicator to provide interruption control and progress logging.

Since:
21 Sep 2022
Author:
Mark Taylor
  • Field Details

    • SEQUENTIAL

      public static final CollectionRunner<?> SEQUENTIAL
      Untyped instance for sequential operation.
    • DFLT

      public static final CollectionRunner<?> DFLT
      Untyped instance using default policy.
  • Constructor Details

    • CollectionRunner

      public CollectionRunner()
      Default constructor, using default policy.
    • CollectionRunner

      public CollectionRunner(uk.ac.starlink.util.SplitProcessor<?> processor)
      Constructs an instance with a given SplitProcessor.
      Parameters:
      processor - controls behaviour
  • Method Details

    • getSplitProcessor

      public uk.ac.starlink.util.SplitProcessor<?> getSplitProcessor()
      Returns this runner's SplitProcessor.
      Returns:
      split processor
    • collect

      public <A> A collect(CollectionRunner.ElementCollector<E,A> collector, Collection<E> collection)
      Performs a collect operation without logging.
      Parameters:
      collector - defines behaviour
      collection - data on which to operate
      Returns:
      result of collection
    • collect

      public <A> A collect(CollectionRunner.ElementCollector<E,A> collector, Collection<E> collection, ProgressIndicator progger)
      Performs a collect operation with optional progress logging.
      Parameters:
      collector - defines behaviour
      collection - data on which to operate
      progger - progress logger
      Returns:
      result of collection
    • collectStream

      public static <E, A> A collectStream(CollectionRunner.ElementCollector<E,A> collector, Stream<E> stream)
      Performs a collection operation using the Java 8 streams framework. This does not use any of the implementation code associated with SplitProcessor, it just creates a Collector based on the supplied ElementCollector and feeds the stream to it.

      This method is only intended for testing and comparison purposes; if you actually want to use Java 8 streams, you might as well use the Collector interface directly.

      Parameters:
      collector - collector
      stream - input stream
      Returns:
      result of collection operation