org.apache.commons.collections.functors
public class SwitchClosure extends Object implements Closure, Serializable
Since: Commons Collections 3.0
Version: $Revision: 348444 $ $Date: 2005-11-23 14:06:56 +0000 (Wed, 23 Nov 2005) $
Constructor Summary | |
---|---|
SwitchClosure(Predicate[] predicates, Closure[] closures, Closure defaultClosure)
Constructor that performs no validation.
|
Method Summary | |
---|---|
void | execute(Object input)
Executes the closure whose matching predicate returns true
|
Closure[] | getClosures()
Gets the closures, do not modify the array.
|
Closure | getDefaultClosure()
Gets the default closure.
|
static Closure | getInstance(Predicate[] predicates, Closure[] closures, Closure defaultClosure)
Factory method that performs validation and copies the parameter arrays.
|
static Closure | getInstance(Map predicatesAndClosures)
Create a new Closure that calls one of the closures depending
on the predicates.
|
Predicate[] | getPredicates()
Gets the predicates, do not modify the array.
|
getInstance
if you want that.
Parameters: predicates array of predicates, not cloned, no nulls closures matching array of closures, not cloned, no nulls defaultClosure the closure to use if no match, null means nop
Parameters: input the input object
Returns: the closures
Since: Commons Collections 3.1
Returns: the default closure
Since: Commons Collections 3.1
Parameters: predicates array of predicates, cloned, no nulls closures matching array of closures, cloned, no nulls defaultClosure the closure to use if no match, null means nop
Returns: the chained
closure
Throws: IllegalArgumentException if array is null IllegalArgumentException if any element in the array is null
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.
Parameters: predicatesAndClosures a map of predicates to closures
Returns: the switch
closure
Throws: IllegalArgumentException if the map is null IllegalArgumentException if any closure in the map is null ClassCastException if the map elements are of the wrong type
Returns: the predicates
Since: Commons Collections 3.1