|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.commons.collections.functors.SwitchClosure<T>
public class SwitchClosure<T>
Closure implementation calls the closure whose predicate returns true, like a switch statement.
| Constructor Summary | |
|---|---|
SwitchClosure(Predicate<? super T>[] predicates,
Closure<? super T>[] closures,
Closure<? super T> defaultClosure)
Constructor that performs no validation. |
|
| Method Summary | ||
|---|---|---|
void |
execute(T input)
Executes the closure whose matching predicate returns true |
|
Closure<? super T>[] |
getClosures()
Gets the closures, do not modify the array. |
|
Closure<? super T> |
getDefaultClosure()
Gets the default closure. |
|
static
|
getInstance(Map<Predicate<? super T>,Closure<? super T>> predicatesAndClosures)
Create a new Closure that calls one of the closures depending on the predicates. |
|
static
|
getInstance(Predicate<? super T>[] predicates,
Closure<? super T>[] closures,
Closure<? super T> defaultClosure)
Factory method that performs validation and copies the parameter arrays. |
|
Predicate<? super T>[] |
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<? super T>[] predicates,
Closure<? super T>[] closures,
Closure<? super T> 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 nop| Method Detail |
|---|
public static <T> Closure<T> getInstance(Predicate<? super T>[] predicates,
Closure<? super T>[] closures,
Closure<? super T> 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
IllegalArgumentException - if array is null
IllegalArgumentException - if any element in the array is nullpublic static <T> Closure<T> getInstance(Map<Predicate<? super T>,Closure<? super T>> predicatesAndClosures)
predicatesAndClosures - a map of predicates to closures
switch closure
IllegalArgumentException - if the map is null
IllegalArgumentException - if any closure in the map is null
ClassCastException - if the map elements are of the wrong typepublic void execute(T input)
execute in interface Closure<T>input - the input objectpublic Predicate<? super T>[] getPredicates()
public Closure<? super T>[] getClosures()
public Closure<? super T> getDefaultClosure()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||