|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.commons.collections4.functors.SwitchClosure<E>
public class SwitchClosure<E>
Closure implementation calls the closure whose predicate returns true, like a switch statement.
Constructor Summary | |
---|---|
SwitchClosure(Predicate<? super E>[] predicates,
Closure<? super E>[] closures,
Closure<? super E> defaultClosure)
Constructor that performs no validation. |
Method Summary | ||
---|---|---|
void |
execute(E input)
Executes the closure whose matching predicate returns true |
|
Closure<? super E>[] |
getClosures()
Gets the closures. |
|
Closure<? super E> |
getDefaultClosure()
Gets the default closure. |
|
Predicate<? super E>[] |
getPredicates()
Gets the predicates. |
|
static
|
switchClosure(Map<Predicate<E>,Closure<E>> predicatesAndClosures)
Create a new Closure that calls one of the closures depending on the predicates. |
|
static
|
switchClosure(Predicate<? super E>[] predicates,
Closure<? super E>[] closures,
Closure<? super E> defaultClosure)
Factory method that performs validation and copies the parameter arrays. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SwitchClosure(Predicate<? super E>[] predicates, Closure<? super E>[] closures, Closure<? super E> defaultClosure)
switchClosure
if you want that.
predicates
- array of predicates, cloned, no nullsclosures
- matching array of closures, cloned, no nullsdefaultClosure
- the closure to use if no match, null means nopMethod Detail |
---|
public static <E> Closure<E> switchClosure(Predicate<? super E>[] predicates, Closure<? super E>[] closures, Closure<? super E> defaultClosure)
E
- the type that the closure acts onpredicates
- 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 <E> Closure<E> switchClosure(Map<Predicate<E>,Closure<E>> 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.
E
- the type that the closure acts onpredicatesAndClosures
- 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(E input)
execute
in interface Closure<E>
input
- the input objectpublic Predicate<? super E>[] getPredicates()
public Closure<? super E>[] getClosures()
public Closure<? super E> getDefaultClosure()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |