Package uk.ac.starlink.table.join
Class CollectionRunner<E>
- java.lang.Object
-
- uk.ac.starlink.table.join.CollectionRunner<E>
-
public class CollectionRunner<E> extends java.lang.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 aProgressIndicator
to provide interruption control and progress logging.- Since:
- 21 Sep 2022
- Author:
- Mark Taylor
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
CollectionRunner.ElementCollector<E,A>
Interface to define a collection operation for use with this class.
-
Field Summary
Fields Modifier and Type Field Description static CollectionRunner<?>
DFLT
Untyped instance using default policy.static CollectionRunner<?>
SEQUENTIAL
Untyped instance for sequential operation.
-
Constructor Summary
Constructors Constructor Description CollectionRunner()
Default constructor, using default policy.CollectionRunner(uk.ac.starlink.util.SplitProcessor<?> processor)
Constructs an instance with a given SplitProcessor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <A> A
collect(CollectionRunner.ElementCollector<E,A> collector, java.util.Collection<E> collection)
Performs a collect operation without logging.<A> A
collect(CollectionRunner.ElementCollector<E,A> collector, java.util.Collection<E> collection, ProgressIndicator progger)
Performs a collect operation with optional progress logging.static <E,A>
AcollectStream(CollectionRunner.ElementCollector<E,A> collector, java.util.stream.Stream<E> stream)
Performs a collection operation using the Java 8 streams framework.uk.ac.starlink.util.SplitProcessor<?>
getSplitProcessor()
Returns this runner's SplitProcessor.
-
-
-
Field Detail
-
SEQUENTIAL
public static final CollectionRunner<?> SEQUENTIAL
Untyped instance for sequential operation.
-
DFLT
public static final CollectionRunner<?> DFLT
Untyped instance using default policy.
-
-
Method Detail
-
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, java.util.Collection<E> collection)
Performs a collect operation without logging.- Parameters:
collector
- defines behaviourcollection
- data on which to operate- Returns:
- result of collection
-
collect
public <A> A collect(CollectionRunner.ElementCollector<E,A> collector, java.util.Collection<E> collection, ProgressIndicator progger)
Performs a collect operation with optional progress logging.- Parameters:
collector
- defines behaviourcollection
- data on which to operateprogger
- progress logger- Returns:
- result of collection
-
collectStream
public static <E,A> A collectStream(CollectionRunner.ElementCollector<E,A> collector, java.util.stream.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 aCollector
based on the suppliedElementCollector
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
- collectorstream
- input stream- Returns:
- result of collection operation
-
-