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