groovyx.gpars.util
Class PAUtils

java.lang.Object
  extended by groovyx.gpars.util.PAUtils

public abstract class PAUtils
extends java.lang.Object

Handy methods build PA from different types

Author:
Vaclav Pech Date: 24th Oct 2010

Constructor Summary
PAUtils()
           
 
Method Summary
static groovy.lang.Closure buildClosureForMaps(groovy.lang.Closure cl)
          If the passed-in closure expects two arguments, it is considered to be a map-iterative code and is then wrapped with a single-argument closure, which unwraps the key:value pairs for the original closure.
static groovy.lang.Closure buildClosureForMapsWithIndex(groovy.lang.Closure cl)
          If the passed-in closure expects three arguments, it is considered to be a map-iterative_with_index code and is then wrapped with a two-argument closure, which unwraps the key:value pairs for the original closure.
static
<K,V> java.util.Map<K,V>
buildResultMap(java.util.Collection<java.util.Map.Entry<K,V>> result)
          Builds a resulting map out of an map entry collection
static java.lang.String[] createArray(java.lang.CharSequence value)
           
static java.util.Map.Entry<java.lang.Object,java.lang.Object>[] createArray(java.util.Map<java.lang.Object,java.lang.Object> map)
           
static java.util.Collection<java.lang.Object> createCollection(java.lang.Iterable<java.lang.Object> object)
           
static java.util.Collection<java.lang.Object> createCollection(java.util.Iterator<java.lang.Object> iterator)
           
static java.util.Comparator<java.lang.Object> createComparator(groovy.lang.Closure handler)
          Builds a comparator depending on the number of arguments accepted by the supplied closure.
static groovy.lang.Closure createGroupByClosure(groovy.lang.Closure cl, java.util.concurrent.ConcurrentMap<java.lang.Object,java.util.List<java.lang.Object>> map)
          Creates a closure that will insert elements in the appropriate group
static void evaluateArguments(Pool pool, java.lang.Object[] args, int current, java.util.List<java.lang.Object> soFarArgs, DataflowVariable<java.lang.Object> result, groovy.lang.Closure original, boolean pooledThreadFlag)
          Performs a single step in the evaluation of parameters passed into an asynchronous function
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PAUtils

public PAUtils()
Method Detail

createCollection

public static java.util.Collection<java.lang.Object> createCollection(java.lang.Iterable<java.lang.Object> object)

createCollection

public static java.util.Collection<java.lang.Object> createCollection(java.util.Iterator<java.lang.Object> iterator)

createArray

public static java.lang.String[] createArray(java.lang.CharSequence value)

createArray

public static java.util.Map.Entry<java.lang.Object,java.lang.Object>[] createArray(java.util.Map<java.lang.Object,java.lang.Object> map)

buildClosureForMaps

public static groovy.lang.Closure buildClosureForMaps(groovy.lang.Closure cl)
If the passed-in closure expects two arguments, it is considered to be a map-iterative code and is then wrapped with a single-argument closure, which unwraps the key:value pairs for the original closure. If the supplied closure doesn't expect two arguments, it is returned unchanged.

Parameters:
cl - The closure to use for parallel methods
Returns:
The original or an unwrapping closure

buildClosureForMapsWithIndex

public static groovy.lang.Closure buildClosureForMapsWithIndex(groovy.lang.Closure cl)
If the passed-in closure expects three arguments, it is considered to be a map-iterative_with_index code and is then wrapped with a two-argument closure, which unwraps the key:value pairs for the original closure. If the supplied closure doesn't expect three arguments, it is returned unchanged.

Parameters:
cl - The closure to use for parallel methods
Returns:
The original or an unwrapping closure

buildResultMap

public static <K,V> java.util.Map<K,V> buildResultMap(java.util.Collection<java.util.Map.Entry<K,V>> result)
Builds a resulting map out of an map entry collection

Parameters:
result - The collection containing map entries
Returns:
A corresponding map instance

createComparator

public static java.util.Comparator<java.lang.Object> createComparator(groovy.lang.Closure handler)
Builds a comparator depending on the number of arguments accepted by the supplied closure.

Parameters:
handler - The one or two argument closure to build a comparator on
Returns:
A new Comparator to use

createGroupByClosure

public static groovy.lang.Closure createGroupByClosure(groovy.lang.Closure cl,
                                                       java.util.concurrent.ConcurrentMap<java.lang.Object,java.util.List<java.lang.Object>> map)
Creates a closure that will insert elements in the appropriate group

Parameters:
cl - The distinction closure
map - The map of groups to contribute to
Returns:
null

evaluateArguments

public static void evaluateArguments(Pool pool,
                                     java.lang.Object[] args,
                                     int current,
                                     java.util.List<java.lang.Object> soFarArgs,
                                     DataflowVariable<java.lang.Object> result,
                                     groovy.lang.Closure original,
                                     boolean pooledThreadFlag)
Performs a single step in the evaluation of parameters passed into an asynchronous function

Parameters:
pool - The thread pool to use
args - The list of original arguments
current - The index of the current argument to evaluate
soFarArgs - A list of arguments evaluated so far
result - The DFV expecting the function result to be bound to once calculated
original - The original non-asynchronous function to invoke once all arguments are available
pooledThreadFlag - Indicates, whether we now run in a pooled thread so we don't have to schedule the original function invocation, once all arguments have been bound

Copyright © 2008–2010 Václav Pech. All Rights Reserved.