|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.commons.collections.functors.SwitchClosure
public class SwitchClosure
Closure implementation calls the closure whose predicate returns true, like a switch statement.
Constructor Summary | |
---|---|
SwitchClosure(Predicate[] predicates,
Closure[] closures,
Closure defaultClosure)
Constructor that performs no validation. |
Method Summary | |
---|---|
void |
execute(java.lang.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(java.util.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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
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 nopMethod Detail |
---|
public 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 nop
chained
closure
java.lang.IllegalArgumentException
- if array is null
java.lang.IllegalArgumentException
- if any element in the array is nullpublic static Closure getInstance(java.util.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 closures
switch
closure
java.lang.IllegalArgumentException
- if the map is null
java.lang.IllegalArgumentException
- if any closure in the map is null
java.lang.ClassCastException
- if the map elements are of the wrong typepublic void execute(java.lang.Object input)
execute
in interface Closure
input
- the input objectpublic Predicate[] getPredicates()
public Closure[] getClosures()
public Closure getDefaultClosure()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |