Top Description Inners Fields Constructors Methods
org.eclipse.collections.impl.parallel

public final Class ParallelIterate

extends Object
Class Inheritance
Imports
java.math.BigDecimal, .BigInteger, java.util.Collection, .List, .RandomAccess, java.util.concurrent.Executor, .ExecutorService, .SynchronousQueue, .ThreadPoolExecutor, .TimeUnit, org.eclipse.collections.api.block.function.Function, .Function0, .Function2, org.eclipse.collections.api.block.function.primitive.DoubleFunction, .FloatFunction, .IntFunction, .LongFunction, org.eclipse.collections.api.block.predicate.Predicate, org.eclipse.collections.api.block.procedure.Procedure, .Procedure2, org.eclipse.collections.api.block.procedure.primitive.ObjectIntProcedure, org.eclipse.collections.api.factory.Maps, org.eclipse.collections.api.factory.primitive.ObjectDoubleMaps, .ObjectLongMaps, org.eclipse.collections.api.list.ListIterable, org.eclipse.collections.api.map.MutableMap, .MutableMapIterable, org.eclipse.collections.api.map.primitive.MutableObjectDoubleMap, .MutableObjectLongMap, .ObjectDoubleMap, .ObjectLongMap, org.eclipse.collections.api.multimap.MutableMultimap, org.eclipse.collections.api.tuple.primitive.DoubleDoublePair, org.eclipse.collections.impl.block.factory.Functions0, org.eclipse.collections.impl.block.procedure.MultimapPutProcedure, .MutatingAggregationProcedure, .NonMutatingAggregationProcedure, org.eclipse.collections.impl.list.fixed.ArrayAdapter, org.eclipse.collections.impl.map.mutable.ConcurrentHashMap, org.eclipse.collections.impl.multimap.list.SynchronizedPutFastListMultimap, org.eclipse.collections.impl.tuple.primitive.PrimitiveTuples, org.eclipse.collections.impl.utility.Iterate

The ParallelIterate class contains several parallel algorithms that work with Collections. All the higher level parallel algorithms depend on the basic parallel algorithm named forEach. The forEach algorithm employs a batching fork and join approach.

All Collections that are not either a RandomAccess or List are first converted to a Java array using Iterate#toArray(Iterable), and then run with one of the ParallelArrayIterate.forEach methods.

See Also
ParallelArrayIterate

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
private static class
private static class
private static class
private static class
private static class
private static class
private static class
private static class
private static class
private static class

Field Summary

Modifier and TypeField and Description
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final ExecutorService
pack-priv static final int

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static <T, K, V> MutableMap<K, V>
aggregateBy(Iterable<T> iterable, Function<? super T, ? extends K> groupBy, Function0<? extends V> zeroValueFactory, Function2<? super V, ? super T, ? extends V> nonMutatingAggregator)

public static <T, K, V, R extends MutableMapIterable<K, V>> R
aggregateBy(Iterable<T> iterable, Function<? super T, ? extends K> groupBy, Function0<? extends V> zeroValueFactory, Function2<? super V, ? super T, ? extends V> nonMutatingAggregator, R mutableMap)

public static <T, K, V> MutableMap<K, V>
aggregateBy(Iterable<T> iterable, Function<? super T, ? extends K> groupBy, Function0<? extends V> zeroValueFactory, Function2<? super V, ? super T, ? extends V> nonMutatingAggregator, int batchSize)

public static <T, K, V, R extends MutableMapIterable<K, V>> R
aggregateBy(Iterable<T> iterable, Function<? super T, ? extends K> groupBy, Function0<? extends V> zeroValueFactory, Function2<? super V, ? super T, ? extends V> nonMutatingAggregator, R mutableMap, int batchSize)

public static <T, K, V> MutableMap<K, V>
aggregateBy(Iterable<T> iterable, Function<? super T, ? extends K> groupBy, Function0<? extends V> zeroValueFactory, Function2<? super V, ? super T, ? extends V> nonMutatingAggregator, int batchSize, Executor executor)

public static <T, K, V, R extends MutableMapIterable<K, V>> R
aggregateBy(Iterable<T> iterable, Function<? super T, ? extends K> groupBy, Function0<? extends V> zeroValueFactory, Function2<? super V, ? super T, ? extends V> nonMutatingAggregator, R mutableMap, int batchSize, Executor executor)

public static <T, K, V> MutableMap<K, V>
aggregateInPlaceBy(Iterable<T> iterable, Function<? super T, ? extends K> groupBy, Function0<? extends V> zeroValueFactory, Procedure2<? super V, ? super T> mutatingAggregator)

public static <T, K, V, R extends MutableMapIterable<K, V>> R
aggregateInPlaceBy(Iterable<T> iterable, Function<? super T, ? extends K> groupBy, Function0<? extends V> zeroValueFactory, Procedure2<? super V, ? super T> mutatingAggregator, R mutableMap)

public static <T, K, V> MutableMap<K, V>
aggregateInPlaceBy(Iterable<T> iterable, Function<? super T, ? extends K> groupBy, Function0<? extends V> zeroValueFactory, Procedure2<? super V, ? super T> mutatingAggregator, int batchSize)

public static <T, K, V, R extends MutableMapIterable<K, V>> R
aggregateInPlaceBy(Iterable<T> iterable, Function<? super T, ? extends K> groupBy, Function0<? extends V> zeroValueFactory, Procedure2<? super V, ? super T> mutatingAggregator, R mutableMap, int batchSize)

public static <T, K, V> MutableMap<K, V>
aggregateInPlaceBy(Iterable<T> iterable, Function<? super T, ? extends K> groupBy, Function0<? extends V> zeroValueFactory, Procedure2<? super V, ? super T> mutatingAggregator, int batchSize, Executor executor)

public static <T, K, V, R extends MutableMapIterable<K, V>> R
aggregateInPlaceBy(Iterable<T> iterable, Function<? super T, ? extends K> groupBy, Function0<? extends V> zeroValueFactory, Procedure2<? super V, ? super T> mutatingAggregator, R mutableMap, int batchSize, Executor executor)

private static <T> int
calculateTaskCount(Iterable<T> iterable, int batchSize)

private static <T> int
calculateTaskCount(BatchIterable<T> batchIterable, int batchSize)

private static int
calculateTaskCount(int size, int batchSize)

public static <T, V> Collection<V>

Returns:

The collected elements. The Collection will be of the same type as the input (List or Set) and will be in the same order as the input (if it is an ordered collection).
collect
(Iterable<T> iterable, Function<? super T, V> function)

Same effect as Iterate#collect(Iterable, Function), but executed in parallel batches.

public static <T, V> Collection<V>

Returns:

The collected elements. The Collection will be of the same type (List or Set) as the input.
collect
(Iterable<T> iterable, Function<? super T, V> function, boolean
If the result can be in a different order. Allowing reordering may yield faster execution.
allowReorderedResult
)

Same effect as Iterate#collect(Iterable, Function), but executed in parallel batches, and with potentially reordered result.

public static <T, V, R extends Collection<V>> R

Returns:

The 'target' collection, with the collected elements added.
collect
(Iterable<T> iterable, Function<? super T, V> function, R
Where to write the output.
target
,
boolean
If the result can be in a different order. Allowing reordering may yield faster execution.
allowReorderedResult
)

Same effect as Iterate#collect(Iterable, Function), but executed in parallel batches, and writing output into the specified collection.

public static <T, V, R extends Collection<V>> R
collect(Iterable<T> iterable, Function<? super T, V> function, R target, int batchSize, Executor executor, boolean allowReorderedResult)

public static <T, V> Collection<V>

Returns:

The collected elements. The Collection will be of the same type as the input (List or Set) and will be in the same order as the input (if it is an ordered collection).
collectIf
(Iterable<T> iterable, Predicate<? super T> predicate, Function<? super T, V> function)

Same effect as Iterate#collectIf(Iterable, Predicate, Function), but executed in parallel batches.

public static <T, V> Collection<V>

Returns:

The collected elements. The Collection will be of the same type as the input (List or Set)
collectIf
(Iterable<T> iterable, Predicate<? super T> predicate, Function<? super T, V> function, boolean
If the result can be in a different order. Allowing reordering may yield faster execution.
allowReorderedResult
)

Same effect as Iterate#collectIf(Iterable, Predicate, Function), but executed in parallel batches, and with potentially reordered results.

public static <T, V, R extends Collection<V>> R

Returns:

The 'target' collection, with the collected elements added.
collectIf
(Iterable<T> iterable, Predicate<? super T> predicate, Function<? super T, V> function, R
Where to write the output.
target
,
boolean
If the result can be in a different order. Allowing reordering may yield faster execution.
allowReorderedResult
)

Same effect as Iterate#collectIf(Iterable, Predicate, Function), but executed in parallel batches, and writing output into the specified collection.

public static <T, V, R extends Collection<V>> R
collectIf(Iterable<T> iterable, Predicate<? super T> predicate, Function<? super T, V> function, R target, int batchSize, Executor executor, boolean allowReorderedResult)

public static <T> int

Returns:

The number of elements which satisfy the predicate.
count
(Iterable<T> iterable, Predicate<? super T> predicate)

Same effect as Iterate#count(Iterable, Predicate), but executed in parallel batches.

public static <T> int

Returns:

The number of elements which satisfy the predicate.
count
(Iterable<T> iterable, Predicate<? super T> predicate, int batchSize, Executor executor)

Same effect as Iterate#count(Iterable, Predicate), but executed in parallel batches.

public static <T, V> Collection<V>
flatCollect(Iterable<T> iterable, Function<? super T, Collection<V>> function)

public static <T, V> Collection<V>
flatCollect(Iterable<T> iterable, Function<? super T, Collection<V>> function, boolean allowReorderedResult)

public static <T, V, R extends Collection<V>> R
flatCollect(Iterable<T> iterable, Function<? super T, Collection<V>> function, R target, boolean allowReorderedResult)

public static <T, V, R extends Collection<V>> R
flatCollect(Iterable<T> iterable, Function<? super T, Collection<V>> function, R target, int batchSize, Executor executor, boolean allowReorderedResult)

public static <T> void
forEach(Iterable<T> iterable, Procedure<? super T> procedure)

Iterate over the collection specified in parallel batches using default runtime parameter values.

public static <T> void
forEach(Iterable<T> iterable, Procedure<? super T> procedure, int batchSize)

Iterate over the collection specified in parallel batches using default runtime parameter values.

public static <T> void
forEach(Iterable<T> iterable, Procedure<? super T> procedure, int batchSize, Executor executor)

public static <T, BT extends Procedure<? super T>> void
forEach(Iterable<T> iterable, BT procedure, Executor
Use this executor for all execution.
executor
)

Iterate over the collection specified in parallel batches using default runtime parameter values and the specified executor.

public static <T, BT extends Procedure<? super T>> void
forEach(Iterable<T> iterable, BT procedure, int
Only run in parallel if input collection is longer than this.
minForkSize
,
int
How many parallel tasks to submit to the executor.

Todo

How does the taskCount relate to the number of threads in the executor?

taskCount
)

Iterate over the collection specified in parallel batches using the specified minimum fork and task count sizes.

public static <T, BT extends Procedure<? super T>> void
forEach(Iterable<T> iterable, BT procedure, int minForkSize, int taskCount, Executor executor)

public static <T, BT extends Procedure<? super T>> void
forEach(Iterable<T> iterable, ProcedureFactory<BT> procedureFactory, Combiner<BT> combiner, Executor executor)

public static <T, BT extends Procedure<? super T>> void
forEach(Iterable<T> iterable, ProcedureFactory<BT> procedureFactory, Combiner<BT> combiner)

public static <T, BT extends Procedure<? super T>> void
forEach(Iterable<T> iterable, ProcedureFactory<BT> procedureFactory, Combiner<BT> combiner, int batchSize)

Iterate over the collection specified in parallel batches using the default values for the task size.

public static <T, BT extends Procedure<? super T>> void
forEach(Iterable<T> iterable, ProcedureFactory<BT> procedureFactory, Combiner<BT> combiner, int batchSize, Executor executor)

public static <T, BT extends Procedure<? super T>> void
forEach(Iterable<T> iterable, ProcedureFactory<BT> procedureFactory, Combiner<BT> combiner, int minForkSize, int taskCount)

Iterate over the collection specified in parallel batches using the default values for the task size.

public static <T, BT extends Procedure<? super T>> void
forEach(Iterable<T> iterable, ProcedureFactory<BT> procedureFactory, Combiner<BT> combiner, int minForkSize, int taskCount, Executor executor)

public static <T, BT extends Procedure<? super T>> void
forEachInBatchWithExecutor(BatchIterable<T> set, ProcedureFactory<BT> procedureFactory, Combiner<BT> combiner, int minForkSize, int taskCount, Executor executor)

public static <T, BT extends Procedure<? super T>> void
forEachInListOnExecutor(List<T> list, ProcedureFactory<BT> procedureFactory, Combiner<BT> combiner, int minForkSize, int taskCount, Executor executor)

public static <T> void
forEachWithIndex(Iterable<T> iterable, ObjectIntProcedure<? super T> objectIntProcedure)

Iterate over the collection specified, in parallel batches using default runtime parameter values.

public static <T, BT extends ObjectIntProcedure<? super T>> void
forEachWithIndex(Iterable<T> iterable, BT procedure, Executor
Use this executor for all execution.
executor
)

Iterate over the collection specified in parallel batches using the default runtime parameters.

public static <T, BT extends ObjectIntProcedure<? super T>> void
forEachWithIndex(Iterable<T> iterable, BT procedure, int
Only run in parallel if input collection is longer than this.
minForkSize
,
int
How many parallel tasks to submit to the executor.
taskCount
)

Iterate over the collection specified in parallel batches.

public static <T, BT extends ObjectIntProcedure<? super T>> void
forEachWithIndex(Iterable<T> iterable, ObjectIntProcedureFactory<BT> procedureFactory, Combiner<BT> combiner, Executor executor)

public static <T, BT extends ObjectIntProcedure<? super T>> void
forEachWithIndex(Iterable<T> iterable, ObjectIntProcedureFactory<BT> procedureFactory, Combiner<BT> combiner, int minForkSize, int taskCount)

public static <T, BT extends ObjectIntProcedure<? super T>> void
forEachWithIndex(Iterable<T> iterable, ObjectIntProcedureFactory<BT> procedureFactory, Combiner<BT> combiner, int minForkSize, int taskCount, Executor executor)

public static <T, BT extends ObjectIntProcedure<? super T>> void
forEachWithIndexInListOnExecutor(List<T> list, ObjectIntProcedureFactory<BT> procedureFactory, Combiner<BT> combiner, int minForkSize, int taskCount, Executor executor)

public static int
public static int
public static int
public static <K, V> MutableMultimap<K, V>
groupBy(Iterable<V> iterable, Function<? super V, ? extends K> function)

Same effect as Iterate#groupBy(Iterable, Function), but executed in parallel batches, and writing output into a SynchronizedPutFastListMultimap.

public static <K, V, R extends MutableMultimap<K, V>> MutableMultimap<K, V>
groupBy(Iterable<V> iterable, Function<? super V, ? extends K> function, R concurrentMultimap)

Same effect as Iterate#groupBy(Iterable, Function), but executed in parallel batches, and writing output into a SynchronizedPutFastListMultimap.

public static <K, V, R extends MutableMultimap<K, V>> MutableMultimap<K, V>
groupBy(Iterable<V> iterable, Function<? super V, ? extends K> function, R concurrentMultimap, int batchSize)

Same effect as Iterate#groupBy(Iterable, Function), but executed in parallel batches, and writing output into a SynchronizedPutFastListMultimap.

public static <K, V> MutableMultimap<K, V>
groupBy(Iterable<V> iterable, Function<? super V, ? extends K> function, int batchSize)

Same effect as Iterate#groupBy(Iterable, Function), but executed in parallel batches, and writing output into a SynchronizedPutFastListMultimap.

public static <K, V> MutableMultimap<K, V>
groupBy(Iterable<V> iterable, Function<? super V, ? extends K> function, int batchSize, Executor executor)

Same effect as Iterate#groupBy(Iterable, Function), but executed in parallel batches, and writing output into a SynchronizedPutFastListMultimap.

public static <K, V, R extends MutableMultimap<K, V>> MutableMultimap<K, V>
groupBy(Iterable<V> iterable, Function<? super V, ? extends K> function, R concurrentMultimap, int batchSize, Executor executor)

Same effect as Iterate#groupBy(Iterable, Function), but executed in parallel batches, and writing output into a SynchronizedPutFastListMultimap.

pack-priv static boolean
public static ExecutorService
newPooledExecutor(int newPoolSize, String poolName, boolean useDaemonThreads)

Returns a brand new ExecutorService using the specified poolName with the specified maximum thread pool size.

public static ExecutorService
newPooledExecutor(String poolName, boolean useDaemonThreads)

Returns a brand new ExecutorService using the specified poolName and uses the optional property named to set the maximum thread pool size.

public static <T> Collection<T>

Returns:

The rejected elements. The Collection will be of the same type as the input (List or Set) and will be in the same order as the input (if it is an ordered collection).
reject
(Iterable<T> iterable, Predicate<? super T> predicate)

Same effect as Iterate#reject(Iterable, Predicate), but executed in parallel batches.

public static <T> Collection<T>

Returns:

The rejected elements. The Collection will be of the same type (List or Set) as the input.
reject
(Iterable<T> iterable, Predicate<? super T> predicate, boolean
If the result can be in a different order. Allowing reordering may yield faster execution.
allowReorderedResult
)

Same effect as Iterate#reject(Iterable, Predicate), but executed in parallel batches, and with a potentially reordered result.

public static <T, R extends Collection<T>> R

Returns:

The 'target' collection, with the rejected elements added.
reject
(Iterable<T> iterable, Predicate<? super T> predicate, R
Where to write the output.
target
,
boolean
If the result can be in a different order. Allowing reordering may yield faster execution.
allowReorderedResult
)

Same effect as Iterate#reject(Iterable, Predicate), but executed in parallel batches, and writing output into the specified collection.

public static <T, R extends Collection<T>> R
reject(Iterable<T> iterable, Predicate<? super T> predicate, R target, int batchSize, Executor executor, boolean allowReorderedResult)

public static <T> Collection<T>

Returns:

The selected elements. The Collection will be of the same type as the input (List or Set) and will be in the same order as the input (if it is an ordered collection).
select
(Iterable<T> iterable, Predicate<? super T> predicate)

Same effect as Iterate#select(Iterable, Predicate), but executed in parallel batches.

public static <T> Collection<T>

Returns:

The selected elements. The Collection will be of the same type (List or Set) as the input.
select
(Iterable<T> iterable, Predicate<? super T> predicate, boolean
If the result can be in a different order. Allowing reordering may yield faster execution.
allowReorderedResult
)

Same effect as Iterate#select(Iterable, Predicate), but executed in parallel batches, and with a potentially reordered result.

public static <T, R extends Collection<T>> R

Returns:

The 'target' collection, with the selected elements added.
select
(Iterable<T> iterable, Predicate<? super T> predicate, R
Where to write the output.
target
,
boolean
If the result can be in a different order. Allowing reordering may yield faster execution.
allowReorderedResult
)

Same effect as Iterate#select(Iterable, Predicate), but executed in parallel batches, and writing output into the specified collection.

public static <T, R extends Collection<T>> R

Returns:

The 'target' collection, with the selected elements added.
select
(Iterable<T> iterable, Predicate<? super T> predicate, R
Where to write the output.
target
,
int batchSize, Executor executor, boolean
If the result can be in a different order. Allowing reordering may yield faster execution.
allowReorderedResult
)

Same effect as Iterate#select(Iterable, Predicate), but executed in parallel batches, and writing output into the specified collection.

pack-priv static void
public static <V, T> MutableMap<V, BigDecimal>
sumByBigDecimal(Iterable<T> iterable, Function<? super T, ? extends V> groupBy, Function<? super T, BigDecimal> function)

public static <V, T> MutableMap<V, BigInteger>
sumByBigInteger(Iterable<T> iterable, Function<? super T, ? extends V> groupBy, Function<? super T, BigInteger> function)

public static <T, V> ObjectDoubleMap<V>
sumByDouble(Iterable<T> iterable, Function<? super T, ? extends V> groupBy, DoubleFunction<? super T> function)

public static <T, V> ObjectDoubleMap<V>
sumByFloat(Iterable<T> iterable, Function<? super T, ? extends V> groupBy, FloatFunction<? super T> function)

public static <T, V> ObjectLongMap<V>
sumByInt(Iterable<T> iterable, Function<? super T, ? extends V> groupBy, IntFunction<? super T> function)

public static <T, V> ObjectLongMap<V>
sumByLong(Iterable<T> iterable, Function<? super T, ? extends V> groupBy, LongFunction<? super T> function)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait