Groovy Documentation

gpars
Class GParsPoolUtil

java.lang.Object
  gpars.GParsPoolUtil

class GParsPoolUtil

This class forms the core of the DSL initialized by GParsPool. The static methods of GParsPoolUtil get attached to their first arguments (the Groovy Category mechanism) and can be then invoked as if they were part of the argument classes.

see:
groovyx.gpars.GParsPool
author:
Vaclav Pech
author:
Robert Fischer Date: Mar 10, 2010


Constructor Summary
GParsPoolUtil()

 
Method Summary
static boolean anyParallel(Collection collection, groovy.lang.Closure cl)

Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied closure as the filter predicate.

static boolean anyParallel(Object collection, groovy.lang.Closure cl)

Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied closure as the filter predicate.

static groovy.lang.Closure async(groovy.lang.Closure cl)

Creates an asynchronous variant of the supplied closure, which, when invoked returns a future for the potential return value

static Future callAsync(groovy.lang.Closure cl, Object args)

Calls a closure in a separate thread supplying the given arguments, returning a future for the potential return value,

static Collection collectParallel(Collection collection, groovy.lang.Closure cl)

Creates a Parallel Array out of the supplied collection/object and invokes the withMapping() method using the supplied closure as the transformation operation.

static Collection collectParallel(Object collection, groovy.lang.Closure cl)

Creates a Parallel Array out of the supplied collection/object and invokes the withMapping() method using the supplied closure as the transformation operation.

static int countParallel(Collection collection, def filter)

Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied rule as the filter predicate.

static int countParallel(Object collection, def filter)

Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied rule as the filter predicate.

static def createCollection(Object object)

static groovy.lang.Closure createComparator(groovy.lang.Closure handler)

Builds a comparator depending on the number of arguments accepted by the supplied closure.

static Collection eachParallel(Collection collection, groovy.lang.Closure cl)

Creates a Parallel Array out of the supplied collection/object and invokes the withMapping() method using the supplied closure as the transformation operation.

static Object eachParallel(Object collection, groovy.lang.Closure cl)

Creates a Parallel Array out of the supplied collection/object and invokes the withMapping() method using the supplied closure as the transformation operation.

static Collection eachWithIndexParallel(Collection collection, groovy.lang.Closure cl)

Creates a Parallel Array out of the supplied collection/object and invokes the withMapping() method using the supplied closure as the transformation operation.

static Object eachWithIndexParallel(Object collection, groovy.lang.Closure cl)

Creates a Parallel Array out of the supplied collection/object and invokes the withMapping() method using the supplied closure as the transformation operation.

static boolean everyParallel(Collection collection, groovy.lang.Closure cl)

Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied closure as the filter predicate.

static boolean everyParallel(Object collection, groovy.lang.Closure cl)

Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied closure as the filter predicate.

static Collection findAllParallel(Collection collection, groovy.lang.Closure cl)

Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied closure as the filter predicate.

static Collection findAllParallel(Object collection, groovy.lang.Closure cl)

Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied closure as the filter predicate.

static Object findAnyParallel(Collection collection, groovy.lang.Closure cl)

Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied closure as the filter predicate.

static Object findAnyParallel(Object collection, groovy.lang.Closure cl)

Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied closure as the filter predicate.

static Object findParallel(Collection collection, groovy.lang.Closure cl)

Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied closure as the filter predicate.

static Object findParallel(Object collection, groovy.lang.Closure cl)

Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied closure as the filter predicate.

static T foldParallel(Collection collection, groovy.lang.Closure cl)

Creates a Parallel Array out of the supplied collection/object and invokes its reduce() method using the supplied closure as the reduction operation.

static Object foldParallel(Object collection, groovy.lang.Closure cl)

Creates a Parallel Array out of the supplied collection/object and invokes its reduce() method using the supplied closure as the reduction operation.

static T foldParallel(Collection collection, def seed, groovy.lang.Closure cl)

Creates a Parallel Array out of the supplied collection/object and invokes its reduce() method using the supplied closure as the reduction operation.

static Object foldParallel(Object collection, def seed, groovy.lang.Closure cl)

Creates a Parallel Array out of the supplied collection/object and invokes its reduce() method using the supplied closure as the reduction operation.

static PAWrapper getParallel(Collection collection)

Creates a PAWrapper around a ParallelArray wrapping te elements of the original collection.

static Object getParallel(Object collection)

Creates a PAWrapper around a ParallelArray wrapping te elements of the original collection.

static Collection grepParallel(Collection collection, def filter)

Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied rule as the filter predicate.

static Object grepParallel(Object collection, def filter)

Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied rule as the filter predicate.

static Map groupByParallel(Collection collection, groovy.lang.Closure cl)

Creates a Parallel Array out of the supplied collection/object and invokes the withMapping() method using the supplied closure as the mapping predicate.

static Map groupByParallel(Object collection, groovy.lang.Closure cl)

Creates a Parallel Array out of the supplied collection/object and invokes the withMapping() method using the supplied closure as the mapping predicate.

static boolean isTransparent(Object collection)

Indicates whether the iterative methods like each() or collect() work have been altered to work concurrently.

static Future leftShift(ForkJoinPool pool, groovy.lang.Closure task)

Submits the task for asynchronous processing returning the Future received from the executor service.

static Object makeTransparent(Object collection)

Creates a TransparentParallel class instance and mixes it in the object it is invoked on.

static T maxParallel(Collection collection, groovy.lang.Closure cl)

Creates a Parallel Array out of the supplied collection/object and invokes its max() method using the supplied closure as the comparator.

static Object maxParallel(Object collection, groovy.lang.Closure cl)

Creates a Parallel Array out of the supplied collection/object and invokes its max() method using the supplied closure as the comparator.

static T maxParallel(Collection collection)

Creates a Parallel Array out of the supplied collection/object and invokes its max() method using the default comparator.

static Object maxParallel(Object collection)

Creates a Parallel Array out of the supplied collection/object and invokes its max() method using the default comparator.

static T minParallel(Collection collection, groovy.lang.Closure cl)

Creates a Parallel Array out of the supplied collection/object and invokes its min() method using the supplied closure as the comparator.

static Object minParallel(Object collection, groovy.lang.Closure cl)

Creates a Parallel Array out of the supplied collection/object and invokes its min() method using the supplied closure as the comparator.

static T minParallel(Collection collection)

Creates a Parallel Array out of the supplied collection/object and invokes its min() method using the default comparator.

static Object minParallel(Object collection)

Creates a Parallel Array out of the supplied collection/object and invokes its min() method using the default comparator.

static Collection splitParallel(Collection collection, def filter)

Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied rule as the filter predicate.

static Object splitParallel(Object collection, def filter)

Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied rule as the filter predicate.

static T sumParallel(Collection collection)

Creates a Parallel Array out of the supplied collection/object and summarizes its elements using the foldParallel() method with the + operator and the reduction operation.

static Object sumParallel(Object collection)

Creates a Parallel Array out of the supplied collection/object and summarizes its elements using the foldParallel() method with the + operator and the reduction operation.

 
Methods inherited from class Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
 

Constructor Detail

GParsPoolUtil

GParsPoolUtil()


 
Method Detail

anyParallel

public static boolean anyParallel(Collection collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied closure as the filter predicate. The closure will be effectively invoked concurrently on the elements of the collection. The anyParallel() method is lazy and once a positive answer has been given by at least one element, it avoids running the supplied closure on subsequent elements. After all the elements have been processed, the method returns a boolean value indicating, whether at least one element of the collection meets the predicate. It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access. Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block have a new anyParallel(Closure cl) method, which delegates to the GParsPoolUtil class. Example: GParsPool.withPool {* assert [1, 2, 3, 4, 5].anyParallel {Number number -> number > 3}* assert ![1, 2, 3].anyParallel {Number number -> number > 3}*}


anyParallel

public static boolean anyParallel(Object collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied closure as the filter predicate. The closure will be effectively invoked concurrently on the elements of the collection. The anyParallel() method is lazy and once a positive answer has been given by at least one element, it avoids running the supplied closure on subsequent elements. After all the elements have been processed, the method returns a boolean value indicating, whether at least one element of the collection meets the predicate. It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access. Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block have a new anyParallel(Closure cl) method, which delegates to the GParsPoolUtil class. Example: GParsPool.withPool {* assert [1, 2, 3, 4, 5].anyParallel {Number number -> number > 3}* assert ![1, 2, 3].anyParallel {Number number -> number > 3}*}


async

public static groovy.lang.Closure async(groovy.lang.Closure cl)
Creates an asynchronous variant of the supplied closure, which, when invoked returns a future for the potential return value


callAsync

public static Future callAsync(groovy.lang.Closure cl, Object args)
Calls a closure in a separate thread supplying the given arguments, returning a future for the potential return value,


collectParallel

public static Collection collectParallel(Collection collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied collection/object and invokes the withMapping() method using the supplied closure as the transformation operation. The closure will be effectively invoked concurrently on the elements of the collection. After all the elements have been processed, the method returns a collection of values from the resulting Parallel Array. It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access. Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block have a new collectParallel(Closure cl) method, which delegates to the GParsPoolUtil class. Example: GParsPool.withPool {* def result = [1, 2, 3, 4, 5].collectParallel {Number number -> number * 10}* assertEquals(new HashSet([10, 20, 30, 40, 50]), result) }


collectParallel

public static Collection collectParallel(Object collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied collection/object and invokes the withMapping() method using the supplied closure as the transformation operation. The closure will be effectively invoked concurrently on the elements of the collection. After all the elements have been processed, the method returns a collection of values from the resulting Parallel Array. It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access. Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block have a new collectParallel(Closure cl) method, which delegates to the GParsPoolUtil class. Example: GParsPool.withPool {* def result = [1, 2, 3, 4, 5].collectParallel {Number number -> number * 10}* assertEquals(new HashSet([10, 20, 30, 40, 50]), result) }


countParallel

public static int countParallel(Collection collection, def filter)
Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied rule as the filter predicate. The filter will be effectively used concurrently on the elements of the collection. After all the elements have been processed, the method returns a collection of values from the resulting Parallel Array. It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access. Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block have a new grepParallel(Closure cl) method, which delegates to the GParsPoolUtil class. Example: GParsPool.withPool {* def result = [1, 2, 3, 4, 5].countParallel(4) assertEquals(1, result) }


countParallel

public static int countParallel(Object collection, def filter)
Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied rule as the filter predicate. The filter will be effectively used concurrently on the elements of the collection. After all the elements have been processed, the method returns a collection of values from the resulting Parallel Array. It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access. Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block have a new grepParallel(Closure cl) method, which delegates to the GParsPoolUtil class. Example: GParsPool.withPool {* def result = [1, 2, 3, 4, 5].countParallel(4) assertEquals(1, result) }


createCollection

public static def createCollection(Object object)


createComparator

@SuppressWarnings("GroovyMultipleReturnPointsPerMethod")
public static groovy.lang.Closure createComparator(groovy.lang.Closure handler)
Builds a comparator depending on the number of arguments accepted by the supplied closure.


eachParallel

public static Collection eachParallel(Collection collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied collection/object and invokes the withMapping() method using the supplied closure as the transformation operation. The closure will be effectively invoked concurrently on the elements of the collection. After all the elements have been processed, the method returns. It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access. Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block have a new eachParallel(Closure cl) method, which delegates to the GParsPoolUtil class. Example: GParsPool.withPool {* def result = new ConcurrentSkipListSet() [1, 2, 3, 4, 5].eachParallel {Number number -> result.add(number * 10)}* assertEquals(new HashSet([10, 20, 30, 40, 50]), result) }* Note that the result variable is synchronized to prevent race conditions between multiple threads.


eachParallel

public static Object eachParallel(Object collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied collection/object and invokes the withMapping() method using the supplied closure as the transformation operation. The closure will be effectively invoked concurrently on the elements of the collection. After all the elements have been processed, the method returns. It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access. Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block have a new eachParallel(Closure cl) method, which delegates to the GParsPoolUtil class. Example: GParsPool.withPool {* def result = new ConcurrentSkipListSet() [1, 2, 3, 4, 5].eachParallel {Number number -> result.add(number * 10)}* assertEquals(new HashSet([10, 20, 30, 40, 50]), result) }* Note that the result variable is synchronized to prevent race conditions between multiple threads.


eachWithIndexParallel

public static Collection eachWithIndexParallel(Collection collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied collection/object and invokes the withMapping() method using the supplied closure as the transformation operation. The closure will be effectively invoked concurrently on the elements of the collection. After all the elements have been processed, the method returns. It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access. Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block have a new eachWithIndexParallel(Closure cl) method, which delegates to the GParsPoolUtil class. Example: GParsPool.withPool {* def result = new ConcurrentSkipListSet() [1, 2, 3, 4, 5].eachWithIndexParallel {Number number, int index -> result.add(number * 10)}* assertEquals(new HashSet([10, 20, 30, 40, 50]), result) }* Note that the result variable is synchronized to prevent race conditions between multiple threads.


eachWithIndexParallel

public static Object eachWithIndexParallel(Object collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied collection/object and invokes the withMapping() method using the supplied closure as the transformation operation. The closure will be effectively invoked concurrently on the elements of the collection. After all the elements have been processed, the method returns. It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access. Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block have a new eachWithIndexParallel(Closure cl) method, which delegates to the GParsPoolUtil class. Example: GParsPool.withPool {* def result = new ConcurrentSkipListSet() [1, 2, 3, 4, 5].eachWithIndexParallel {Number number, int index -> result.add(number * 10)}* assertEquals(new HashSet([10, 20, 30, 40, 50]), result) }* Note that the result variable is synchronized to prevent race conditions between multiple threads.


everyParallel

public static boolean everyParallel(Collection collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied closure as the filter predicate. The closure will be effectively invoked concurrently on the elements of the collection. After all the elements have been processed, the method returns a boolean value indicating, whether all the elements of the collection meet the predicate. It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access. Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block have a new everyParallel(Closure cl) method, which delegates to the GParsPoolUtil class. Example: GParsPool.withPool(5) {* assert ![1, 2, 3, 4, 5].everyParallel {Number number -> number > 3}* assert [1, 2, 3].everyParallel() {Number number -> number <= 3}*}


everyParallel

public static boolean everyParallel(Object collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied closure as the filter predicate. The closure will be effectively invoked concurrently on the elements of the collection. After all the elements have been processed, the method returns a boolean value indicating, whether all the elements of the collection meet the predicate. It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access. Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block have a new everyParallel(Closure cl) method, which delegates to the GParsPoolUtil class. Example: GParsPool.withPool(5) {* assert ![1, 2, 3, 4, 5].everyParallel {Number number -> number > 3}* assert [1, 2, 3].everyParallel() {Number number -> number <= 3}*}


findAllParallel

public static Collection findAllParallel(Collection collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied closure as the filter predicate. The closure will be effectively invoked concurrently on the elements of the collection. After all the elements have been processed, the method returns a collection of values from the resulting Parallel Array. It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access. Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block have a new findAllParallel(Closure cl) method, which delegates to the GParsPoolUtil class. Example: GParsPool.withPool {* def result = [1, 2, 3, 4, 5].findAllParallel {Number number -> number > 3}* assertEquals(new HashSet([4, 5]), result) }


findAllParallel

public static Collection findAllParallel(Object collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied closure as the filter predicate. The closure will be effectively invoked concurrently on the elements of the collection. After all the elements have been processed, the method returns a collection of values from the resulting Parallel Array. It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access. Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block have a new findAllParallel(Closure cl) method, which delegates to the GParsPoolUtil class. Example: GParsPool.withPool {* def result = [1, 2, 3, 4, 5].findAllParallel {Number number -> number > 3}* assertEquals(new HashSet([4, 5]), result) }


findAnyParallel

public static Object findAnyParallel(Collection collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied closure as the filter predicate. Unlike with the find method, findAnyParallel() does not guarantee that the a matching element with the lowest index is returned. The findAnyParallel() method evaluates elements lazily and stops processing further elements of the collection once a match has been found. The closure will be effectively invoked concurrently on the elements of the collection. After all the elements have been processed, the method returns a random value from the resulting Parallel Array. It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access. Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block have a new findParallel(Closure cl) method, which delegates to the GParsPoolUtil class. Example: GParsPool.withPool {* def result = [1, 2, 3, 4, 5].findParallel {Number number -> number > 3}* assert (result in [4, 5]) }


findAnyParallel

public static Object findAnyParallel(Object collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied closure as the filter predicate. Unlike with the find method, findAnyParallel() does not guarantee that the a matching element with the lowest index is returned. The findAnyParallel() method evaluates elements lazily and stops processing further elements of the collection once a match has been found. The closure will be effectively invoked concurrently on the elements of the collection. After all the elements have been processed, the method returns a random value from the resulting Parallel Array. It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access. Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block have a new findParallel(Closure cl) method, which delegates to the GParsPoolUtil class. Example: GParsPool.withPool {* def result = [1, 2, 3, 4, 5].findParallel {Number number -> number > 3}* assert (result in [4, 5]) }


findParallel

public static Object findParallel(Collection collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied closure as the filter predicate. The closure will be effectively invoked concurrently on the elements of the collection. After all the elements have been processed, the method returns a value from the resulting Parallel Array with the minimum index. It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access. Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block have a new findParallel(Closure cl) method, which delegates to the GParsPoolUtil class. Example: GParsPool.withPool {* def result = [1, 2, 3, 4, 5].findParallel {Number number -> number > 3}* assert (result in [4, 5]) }


findParallel

public static Object findParallel(Object collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied closure as the filter predicate. The closure will be effectively invoked concurrently on the elements of the collection. After all the elements have been processed, the method returns a value from the resulting Parallel Array with the minimum index. It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access. Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block have a new findParallel(Closure cl) method, which delegates to the GParsPoolUtil class. Example: GParsPool.withPool {* def result = [1, 2, 3, 4, 5].findParallel {Number number -> number > 3}* assert (result in [4, 5]) }


foldParallel

public static T foldParallel(Collection collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied collection/object and invokes its reduce() method using the supplied closure as the reduction operation. The closure will be effectively invoked concurrently on the elements of the collection. After all the elements have been processed, the method returns the reduction result of the elements in the collection. It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access. Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block have a new min(Closure cl) method, which delegates to the GParsPoolUtil class.


foldParallel

public static Object foldParallel(Object collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied collection/object and invokes its reduce() method using the supplied closure as the reduction operation. The closure will be effectively invoked concurrently on the elements of the collection. After all the elements have been processed, the method returns the reduction result of the elements in the collection. It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access. Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block have a new min(Closure cl) method, which delegates to the GParsPoolUtil class.


foldParallel

public static T foldParallel(Collection collection, def seed, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied collection/object and invokes its reduce() method using the supplied closure as the reduction operation. The closure will be effectively invoked concurrently on the elements of the collection. After all the elements have been processed, the method returns the reduction result of the elements in the collection. It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access. Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block have a new min(Closure cl) method, which delegates to the GParsPoolUtil class.
param:
seed A seed value to initialize the operation


foldParallel

public static Object foldParallel(Object collection, def seed, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied collection/object and invokes its reduce() method using the supplied closure as the reduction operation. The closure will be effectively invoked concurrently on the elements of the collection. After all the elements have been processed, the method returns the reduction result of the elements in the collection. It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access. Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block have a new min(Closure cl) method, which delegates to the GParsPoolUtil class.
param:
seed A seed value to initialize the operation


getParallel

public static PAWrapper getParallel(Collection collection)
Creates a PAWrapper around a ParallelArray wrapping te elements of the original collection. This allows further parallel processing operations on the collection to chain and so effectively leverage the underlying ParallelArray implementation.


getParallel

public static Object getParallel(Object collection)
Creates a PAWrapper around a ParallelArray wrapping te elements of the original collection. This allows further parallel processing operations on the collection to chain and so effectively leverage the underlying ParallelArray implementation.


grepParallel

public static Collection grepParallel(Collection collection, def filter)
Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied rule as the filter predicate. The filter will be effectively used concurrently on the elements of the collection. After all the elements have been processed, the method returns a collection of values from the resulting Parallel Array. It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access. Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block have a new grepParallel(Closure cl) method, which delegates to the GParsPoolUtil class. Example: GParsPool.withPool {* def result = [1, 2, 3, 4, 5].grepParallel(4..6) assertEquals(new HashSet([4, 5]), result) }


grepParallel

public static Object grepParallel(Object collection, def filter)
Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied rule as the filter predicate. The filter will be effectively used concurrently on the elements of the collection. After all the elements have been processed, the method returns a collection of values from the resulting Parallel Array. It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access. Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block have a new grepParallel(Closure cl) method, which delegates to the GParsPoolUtil class. Example: GParsPool.withPool {* def result = [1, 2, 3, 4, 5].grepParallel(4..6) assertEquals(new HashSet([4, 5]), result) }


groupByParallel

public static Map groupByParallel(Collection collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied collection/object and invokes the withMapping() method using the supplied closure as the mapping predicate. The closure will be effectively invoked concurrently on the elements of the collection. After all the elements have been processed, the method returns a list of groups of the original elements. Elements in the same group gave identical results when the supplied closure was invoked on them. It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access. Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block have a new groupByParallel(Closure cl) method, which delegates to the GParsPoolUtil class. Example: GParsPool.withPool {* assert ([1, 2, 3, 4, 5].groupByParallel {Number number -> number % 2}).size() == 2 }


groupByParallel

public static Map groupByParallel(Object collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied collection/object and invokes the withMapping() method using the supplied closure as the mapping predicate. The closure will be effectively invoked concurrently on the elements of the collection. After all the elements have been processed, the method returns a list of groups of the original elements. Elements in the same group gave identical results when the supplied closure was invoked on them. It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access. Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block have a new groupByParallel(Closure cl) method, which delegates to the GParsPoolUtil class. Example: GParsPool.withPool {* assert ([1, 2, 3, 4, 5].groupByParallel {Number number -> number % 2}).size() == 2 }


isTransparent

public static boolean isTransparent(Object collection)
Indicates whether the iterative methods like each() or collect() work have been altered to work concurrently.


leftShift

public static Future leftShift(ForkJoinPool pool, groovy.lang.Closure task)
Submits the task for asynchronous processing returning the Future received from the executor service. Allows for the following syntax:
 executorService << {println 'Inside parallel task'}* 


makeTransparent

public static Object makeTransparent(Object collection)
Creates a TransparentParallel class instance and mixes it in the object it is invoked on. The TransparentParallel class overrides the iterative methods like each(), collect() and such, so that they call their parallel variants from the GParsPoolUtil class like eachParallel(), collectParallel() and such. After mixing-in, the isTransparent() method will return true.
param:
collection The object to make transparent
return:
The instance of the TransparentParallel class wrapping the original object and overriding the iterative methods with new parallel behavior


maxParallel

public static T maxParallel(Collection collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied collection/object and invokes its max() method using the supplied closure as the comparator. The closure will be effectively invoked concurrently on the elements of the collection. After all the elements have been processed, the method returns the maximum of the elements in the collection. It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access. Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block have a new min(Closure cl) method, which delegates to the GParsPoolUtil class. If the supplied closure takes two arguments it is used directly as a comparator. If the supplied closure takes one argument, the values returned by the supplied closure for individual elements are used for comparison by the implicit comparator.
param:
cl A one or two-argument closure


maxParallel

public static Object maxParallel(Object collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied collection/object and invokes its max() method using the supplied closure as the comparator. The closure will be effectively invoked concurrently on the elements of the collection. After all the elements have been processed, the method returns the maximum of the elements in the collection. It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access. Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block have a new min(Closure cl) method, which delegates to the GParsPoolUtil class. If the supplied closure takes two arguments it is used directly as a comparator. If the supplied closure takes one argument, the values returned by the supplied closure for individual elements are used for comparison by the implicit comparator.
param:
cl A one or two-argument closure


maxParallel

public static T maxParallel(Collection collection)
Creates a Parallel Array out of the supplied collection/object and invokes its max() method using the default comparator. The closure will be effectively invoked concurrently on the elements of the collection. After all the elements have been processed, the method returns the maximum of the elements in the collection. Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block have a new min(Closure cl) method, which delegates to the GParsPoolUtil class.


maxParallel

public static Object maxParallel(Object collection)
Creates a Parallel Array out of the supplied collection/object and invokes its max() method using the default comparator. The closure will be effectively invoked concurrently on the elements of the collection. After all the elements have been processed, the method returns the maximum of the elements in the collection. Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block have a new min(Closure cl) method, which delegates to the GParsPoolUtil class.


minParallel

public static T minParallel(Collection collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied collection/object and invokes its min() method using the supplied closure as the comparator. The closure will be effectively invoked concurrently on the elements of the collection. After all the elements have been processed, the method returns the minimum of the elements in the collection. It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access. Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block have a new min(Closure cl) method, which delegates to the GParsPoolUtil class. If the supplied closure takes two arguments it is used directly as a comparator. If the supplied closure takes one argument, the values returned by the supplied closure for individual elements are used for comparison by the implicit comparator.
param:
cl A one or two-argument closure


minParallel

public static Object minParallel(Object collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied collection/object and invokes its min() method using the supplied closure as the comparator. The closure will be effectively invoked concurrently on the elements of the collection. After all the elements have been processed, the method returns the minimum of the elements in the collection. It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access. Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block have a new min(Closure cl) method, which delegates to the GParsPoolUtil class. If the supplied closure takes two arguments it is used directly as a comparator. If the supplied closure takes one argument, the values returned by the supplied closure for individual elements are used for comparison by the implicit comparator.
param:
cl A one or two-argument closure


minParallel

public static T minParallel(Collection collection)
Creates a Parallel Array out of the supplied collection/object and invokes its min() method using the default comparator. The closure will be effectively invoked concurrently on the elements of the collection. After all the elements have been processed, the method returns the minimum of the elements in the collection. Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block have a new min(Closure cl) method, which delegates to the GParsPoolUtil class.


minParallel

public static Object minParallel(Object collection)
Creates a Parallel Array out of the supplied collection/object and invokes its min() method using the default comparator. The closure will be effectively invoked concurrently on the elements of the collection. After all the elements have been processed, the method returns the minimum of the elements in the collection. Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block have a new min(Closure cl) method, which delegates to the GParsPoolUtil class.


splitParallel

public static Collection splitParallel(Collection collection, def filter)
Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied rule as the filter predicate. The filter will be effectively used concurrently on the elements of the collection. After all the elements have been processed, the method returns a collection of values from the resulting Parallel Array. It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access. Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block have a new grepParallel(Closure cl) method, which delegates to the GParsPoolUtil class. Example: GParsPool.withPool {* def result = [1, 2, 3, 4, 5].splitParallel(it > 3) assert [3, 4, 5] as Set == result[0] as Set assert [1, 2] as Set == result[1] as Set }


splitParallel

public static Object splitParallel(Object collection, def filter)
Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied rule as the filter predicate. The filter will be effectively used concurrently on the elements of the collection. After all the elements have been processed, the method returns a collection of values from the resulting Parallel Array. It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access. Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block have a new grepParallel(Closure cl) method, which delegates to the GParsPoolUtil class. Example: GParsPool.withPool {* def result = [1, 2, 3, 4, 5].splitParallel(4..6) assert [3, 4, 5] as Set == result[0] as Set assert [1, 2] as Set == result[1] as Set }


sumParallel

public static T sumParallel(Collection collection)
Creates a Parallel Array out of the supplied collection/object and summarizes its elements using the foldParallel() method with the + operator and the reduction operation. The closure will be effectively invoked concurrently on the elements of the collection. After all the elements have been processed, the method returns the sum of the elements in the collection. Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block have a new min(Closure cl) method, which delegates to the GParsPoolUtil class.


sumParallel

public static Object sumParallel(Object collection)
Creates a Parallel Array out of the supplied collection/object and summarizes its elements using the foldParallel() method with the + operator and the reduction operation. The closure will be effectively invoked concurrently on the elements of the collection. After all the elements have been processed, the method returns the sum of the elements in the collection. Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block have a new min(Closure cl) method, which delegates to the GParsPoolUtil class.


 

Groovy Documentation