java.lang.Object | +--org.apache.commons.collections.ClosureUtils
This class is not normally instantiated. |
static Closure | asClosure(Transformer transformer) Creates a Closure that calls a Transformer each time it is called. |
static Closure | chainedClosure(Closure closure1, Closure closure2) Create a new Closure that calls two Closures, passing the result of the first into the second. |
static Closure | chainedClosure(Closure closures) Create a new Closure that calls each closure in turn, passing the result into the next closure. |
static Closure | chainedClosure(Collection closures) Create a new Closure that calls each closure in turn, passing the result into the next closure. |
static Closure | doWhileClosure(Closure closure, Predicate predicate) Creates a Closure that will call the closure once and then repeatedly until the predicate returns false. |
static Closure | Gets a Closure that always throws an exception. |
static Closure | forClosure(int count, Closure closure) Creates a Closure that will call the closure count times. |
static Closure | ifClosure(Predicate predicate, Closure trueClosure, Closure falseClosure) Create a new Closure that calls one of two closures depending on the specified predicate. |
static Closure | invokerClosure(String methodName) Creates a Closure that will invoke a specific method on the closure's input object by reflection. |
static Closure | invokerClosure(String methodName, Class[] paramTypes, Object[] args) Creates a Closure that will invoke a specific method on the closure's input object by reflection. |
static Closure | Gets a Closure that will do nothing. |
static Closure | switchClosure(Predicate[] predicates, Closure closures) Create a new Closure that calls one of the closures depending on the predicates. |
static Closure | switchClosure(Predicate[] predicates, Closure closures, Closure defaultClosure) Create a new Closure that calls one of the closures depending on the predicates. |
static Closure | switchClosure(Map predicatesAndClosures) Create a new Closure that calls one of the closures depending on the predicates. |
static Closure | switchMapClosure(Map objectsAndClosures) Create a new Closure that uses the input object as a key to find the closure to call. |
static Closure | whileClosure(Predicate predicate, Closure closure) Creates a Closure that will call the closure repeatedly until the predicate returns false. |
public ClosureUtils()
public static Closure asClosure(Transformer transformer)
public static Closure chainedClosure(Collection closures)
- if the closures collection is null
- if the closures collection is empty
- if any closure in the collection is nullpublic static Closure chainedClosure(Closure closure1, Closure closure2)
- if either closure is nullpublic static Closure chainedClosure(Closure closures)
- if the closures array is null
- if any closure in the array is nullpublic static Closure doWhileClosure(Closure closure, Predicate predicate)
- if either argument is nullpublic static Closure exceptionClosure()
public static Closure forClosure(int count, Closure closure)
count
times.
A null closure or zero count returns the NOPClosure
.
public static Closure ifClosure(Predicate predicate, Closure trueClosure, Closure falseClosure)
- if the predicate is null
- if either closure is nullpublic static Closure invokerClosure(String methodName, Class[] paramTypes, Object[] args)
- if the method name is null
- if the paramTypes and args don't matchpublic static Closure invokerClosure(String methodName)
- if the method name is nullpublic static Closure nopClosure()
public static Closure switchClosure(Map predicatesAndClosures)
- if the map is null
- if the map is empty
- if any closure in the map is null
- if the map elements are of the wrong typepublic static Closure switchClosure(Predicate[] predicates, Closure closures, Closure defaultClosure)
- if the either array is null
- if any element in the arrays is null
- if the arrays are different sizespublic static Closure switchClosure(Predicate[] predicates, Closure closures)
- if the either array is null
- if any element in the arrays is null
- if the arrays are different sizespublic static Closure switchMapClosure(Map objectsAndClosures)
- if the map is null
- if the map is empty
- if any closure in the map is nullpublic static Closure whileClosure(Predicate predicate, Closure closure)
- if either argument is null
ClosureUtils
provides reference implementations and utilities for the Closure functor interface. The supplied closures are:- Invoker - invokes a method on the input object
- For - repeatedly calls a closure for a fixed number of times
- While - repeatedly calls a closure while a predicate is true
- DoWhile - repeatedly calls a closure while a predicate is true
- Chained - chains two or more closures together
- Switch - calls one closure based on one or more predicates
- SwitchMap - calls one closure looked up from a Map
- Transformer - wraps a Transformer as a Closure
- NOP - does nothing
- Exception - always throws an exception
All the supplied closures are Serializable.