ClosureUtils provides reference implementations and utilities
for the Closure functor interface. The supplied closures are:
Since v4.1 only closures which are considered to be safe are Serializable. Closures considered to be unsafe for serialization are:
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static < the type that the closure acts on E> Closure | Returns: the closurethe transformer to run each time in the closure, null means nop transformer)Creates a Closure that calls a Transformer each time it is called. |
| public static < the type that the closure acts on E> Closure | Returns: thechained closurean array of closures to chain closures)Create a new Closure that calls each closure in turn, passing the result into the next closure. |
| public static < the type that the closure acts on E> Closure | Returns: thechained closurea collection of closures to chain closures)Create a new Closure that calls each closure in turn, passing the result into the next closure. |
| public static < the type that the closure acts on E> Closure | Returns: thedo-while closurethe closure to call repeatedly, not null closure, final Predicate<? super E> the predicate to use as an end of loop test, not null predicate)Creates a Closure that will call the closure once and then repeatedly until the predicate returns false. |
| public static < the type that the closure acts on E> Closure | |
| public static < the type that the closure acts on E> Closure | Returns: thefor closurethe number of times to loop count, final Closure<? super E> the closure to call repeatedly closure)Creates a Closure that will call the closure |
| public static < the type that the closure acts on E> Closure | |
| public static < the type that the closure acts on E> Closure | Returns: theswitch closurethe predicate to switch on predicate, final Closure<? super E> the closure called if the predicate is true trueClosure, final Closure<? super E> the closure called if the predicate is false falseClosure)Create a new Closure that calls one of two closures depending on the specified predicate. |
| public static < the type that the closure acts on E> Closure | Returns: theinvoker closurethe name of the method methodName)Creates a Closure that will invoke a specific method on the closure's input object by reflection. |
| public static < the type that the closure acts on E> Closure | Returns: theinvoker closurethe name of the method methodName, final Class<?>[] the parameter types paramTypes, final Object[] the arguments args)Creates a Closure that will invoke a specific method on the closure's input object by reflection. |
| public static < the type that the closure acts on E> Closure | |
| public static < the type that the closure acts on E> Closure | Returns: theswitch closurean array of predicates to check, not null predicates, final Closure<? super E>[] an array of closures to call, not null closures)Create a new Closure that calls one of the closures depending on the predicates. |
| public static < the type that the closure acts on E> Closure | Returns: theswitch closurean array of predicates to check, not null predicates, final Closure<? super E>[] an array of closures to call, not null closures, final Closure<? super E> the default to call if no predicate matches defaultClosure)Create a new Closure that calls one of the closures depending on the predicates. |
| public static < the type that the closure acts on E> Closure | Returns: theswitch closurea map of predicates to closures predicatesAndClosures)Create a new Closure that calls one of the closures depending on the predicates. |
| public static < the type that the closure acts on E> Closure | Returns: the closurea map of objects to closures objectsAndClosures)Create a new Closure that uses the input object as a key to find the closure to call. |
| public static < the type that the closure acts on E> Closure | Returns: thewhile closurethe predicate to use as an end of loop test, not null predicate, final Closure<? super E> the closure to call repeatedly, not null closure)Creates a Closure that will call the closure repeatedly until the predicate returns false. |
| ClosureUtils | back to summary |
|---|---|
| private ClosureUtils() This class is not normally instantiated. | |
| asClosure | back to summary |
|---|---|
| public static <E> Closure Creates a Closure that calls a Transformer each time it is called. The transformer will be called using the closure's input object. The transformer's result will be ignored.
| |
| chainedClosure | back to summary |
|---|---|
| public static <E> Closure Create a new Closure that calls each closure in turn, passing the result into the next closure.
| |
| chainedClosure | back to summary |
|---|---|
| public static <E> Closure Create a new Closure that calls each closure in turn, passing the result into the next closure. The ordering is that of the iterator() method on the collection.
| |
| doWhileClosure | back to summary |
|---|---|
| public static <E> Closure Creates a Closure that will call the closure once and then repeatedly until the predicate returns false.
| |
| exceptionClosure | back to summary |
|---|---|
| public static <E> Closure Gets a Closure that always throws an exception. This could be useful during testing as a placeholder.
| |
| forClosure | back to summary |
|---|---|
| public static <E> Closure Creates a Closure that will call the closure
A null closure or zero count returns the
| |
| ifClosure | back to summary |
|---|---|
| public static <E> Closure Create a new Closure that calls another closure based on the result of the specified predicate.
| |
| ifClosure | back to summary |
|---|---|
| public static <E> Closure Create a new Closure that calls one of two closures depending on the specified predicate.
| |
| invokerClosure | back to summary |
|---|---|
| public static <E> Closure Creates a Closure that will invoke a specific method on the closure's input object by reflection.
| |
| invokerClosure | back to summary |
|---|---|
| public static <E> Closure Creates a Closure that will invoke a specific method on the closure's input object by reflection.
| |
| nopClosure | back to summary |
|---|---|
| public static <E> Closure Gets a Closure that will do nothing. This could be useful during testing as a placeholder.
| |
| switchClosure | back to summary |
|---|---|
| public static <E> Closure Create a new Closure that calls one of the closures depending on the predicates. The closure at array location 0 is called if the predicate at array location 0 returned true. Each predicate is evaluated until one returns true.
| |
| switchClosure | back to summary |
|---|---|
| public static <E> Closure Create a new Closure that calls one of the closures depending on the predicates. The closure at array location 0 is called if the predicate at array location 0 returned true. Each predicate is evaluated until one returns true. If no predicates evaluate to true, the default closure is called.
| |
| switchClosure | back to summary |
|---|---|
| public static <E> Closure Create a new Closure that calls one of the closures depending on the predicates. The Map consists of Predicate keys and Closure values. A closure is called if its matching predicate returns true. Each predicate is evaluated until one returns true. If no predicates evaluate to true, the default closure is called. The default closure is set in the map with a null key. The ordering is that of the iterator() method on the entryset collection of the map.
| |
| switchMapClosure | back to summary |
|---|---|
| public static <E> Closure Create a new Closure that uses the input object as a key to find the closure to call. The Map consists of object keys and Closure values. A closure is called if the input object equals the key. If there is no match, the default closure is called. The default closure is set in the map using a null key.
| |
| whileClosure | back to summary |
|---|---|
| public static <E> Closure Creates a Closure that will call the closure repeatedly until the predicate returns false.
| |