public class SwitchClosure<E> extends java.lang.Object implements Closure<E>, java.io.Serializable
Constructor and Description |
---|
SwitchClosure(Predicate<? super E>[] predicates,
Closure<? super E>[] closures,
Closure<? super E> defaultClosure)
Constructor that performs no validation.
|
Modifier and Type | Method and Description |
---|---|
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 <E> Closure<E> |
switchClosure(java.util.Map<Predicate<E>,Closure<E>> predicatesAndClosures)
Create a new Closure that calls one of the closures depending
on the predicates.
|
static <E> Closure<E> |
switchClosure(Predicate<? super E>[] predicates,
Closure<? super E>[] closures,
Closure<? super E> defaultClosure)
Factory method that performs validation and copies the parameter arrays.
|
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 noppublic 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 nopchained
closurejava.lang.NullPointerException
- if array is nulljava.lang.NullPointerException
- if any element in the array is nulljava.lang.IllegalArgumentException
- if the array lengths of predicates and closures do not matchpublic static <E> Closure<E> switchClosure(java.util.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 closuresswitch
closurejava.lang.NullPointerException
- if the map is nulljava.lang.NullPointerException
- if any closure in the map is nulljava.lang.ClassCastException
- if the map elements are of the wrong typepublic void execute(E input)
public Predicate<? super E>[] getPredicates()
public Closure<? super E>[] getClosures()
"Copyright © 2010 - 2020 Adobe Systems Incorporated. All Rights Reserved"