public class SwitchClosure extends java.lang.Object implements Closure, java.io.Serializable
Constructor and Description |
---|
SwitchClosure(Predicate[] predicates,
Closure[] closures,
Closure defaultClosure)
Constructor that performs no validation.
|
Modifier and Type | Method and Description |
---|---|
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.
|
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
closurejava.lang.IllegalArgumentException
- if array is nulljava.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 closuresswitch
closurejava.lang.IllegalArgumentException
- if the map is nulljava.lang.IllegalArgumentException
- if any closure in the map is nulljava.lang.ClassCastException
- if the map elements are of the wrong typepublic void execute(java.lang.Object input)
public Predicate[] getPredicates()
public Closure[] getClosures()
public Closure getDefaultClosure()
Copyright © 2010 - 2020 Adobe. All Rights Reserved