public class SwitchClosure extends Object implements Closure, Serializable
Constructor and Description |
---|
SwitchClosure(Predicate[] predicates,
Closure[] closures,
Closure defaultClosure)
Constructor that performs no validation.
|
Modifier and Type | Method and Description |
---|---|
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(Map predicatesAndClosures)
Create a new Closure that calls one of the closures depending
on the predicates.
|
static Closure |
getInstance(Predicate[] predicates,
Closure[] closures,
Closure defaultClosure)
Factory method that performs validation and copies the parameter arrays.
|
Predicate[] |
getPredicates()
Gets the predicates, do not modify the array.
|
public SwitchClosure(Predicate[] predicates, Closure[] closures, Closure defaultClosure)
getInstance
if you want that.predicates
- array of predicates, not cloned, no nullsclosures
- matching array of closures, not cloned, no nullsdefaultClosure
- the closure to use if no match, null means noppublic static Closure getInstance(Predicate[] predicates, Closure[] closures, Closure defaultClosure)
predicates
- array of predicates, cloned, no nullsclosures
- matching array of closures, cloned, no nullsdefaultClosure
- the closure to use if no match, null means nopchained
closureIllegalArgumentException
- if array is nullIllegalArgumentException
- if any element in the array is nullpublic static Closure getInstance(Map predicatesAndClosures)
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.
predicatesAndClosures
- a map of predicates to closuresswitch
closureIllegalArgumentException
- if the map is nullIllegalArgumentException
- if any closure in the map is nullClassCastException
- if the map elements are of the wrong typepublic void execute(Object input)
public Predicate[] getPredicates()
public Closure[] getClosures()
public Closure getDefaultClosure()
Copyright © 2001–2015 The Apache Software Foundation. All rights reserved.