Class SwitchClosure
java.lang.Object
org.apache.commons.collections.functors.SwitchClosure
- All Implemented Interfaces:
Serializable
,Closure
@Deprecated(since="2021-04-30")
public class SwitchClosure
extends Object
implements Closure, Serializable
Deprecated.
Apache Commons Collections version 3.x is being deprecated from AEMaaCS. The upgraded version 4.4 of Commons Collections is already included as replacement. Customers are advised to upgrade to this version of the library. Please note: the package name was changed to org.apache.commons.collections4. Further note that there are AEM APIs currently exposing the old collections classes; these will be updated in upcoming releases.
Closure implementation calls the closure whose predicate returns true,
like a switch statement.
- Since:
- Commons Collections 3.0
- See Also:
-
Constructor Summary
ConstructorDescriptionSwitchClosure
(Predicate[] predicates, Closure[] closures, Closure defaultClosure) Deprecated.Constructor that performs no validation. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Deprecated.Executes the closure whose matching predicate returns trueClosure[]
Deprecated.Gets the closures, do not modify the array.Deprecated.Gets the default closure.static Closure
getInstance
(Map predicatesAndClosures) Deprecated.Create a new Closure that calls one of the closures depending on the predicates.static Closure
getInstance
(Predicate[] predicates, Closure[] closures, Closure defaultClosure) Deprecated.Factory method that performs validation and copies the parameter arrays.Deprecated.Gets the predicates, do not modify the array.
-
Constructor Details
-
SwitchClosure
Deprecated.Constructor that performs no validation. UsegetInstance
if you want that.- Parameters:
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 Details
-
getInstance
public static Closure getInstance(Predicate[] predicates, Closure[] closures, Closure defaultClosure) Deprecated.Factory method that performs validation and copies the parameter arrays.- Parameters:
predicates
- array of predicates, cloned, no nullsclosures
- matching array of closures, cloned, no nullsdefaultClosure
- the closure to use if no match, null means nop- Returns:
- the
chained
closure - Throws:
IllegalArgumentException
- if array is nullIllegalArgumentException
- if any element in the array is null
-
getInstance
Deprecated.Create a new Closure that calls one of the closures depending on the predicates.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.
- Parameters:
predicatesAndClosures
- a map of predicates to closures- Returns:
- the
switch
closure - Throws:
IllegalArgumentException
- if the map is nullIllegalArgumentException
- if any closure in the map is nullClassCastException
- if the map elements are of the wrong type
-
execute
Deprecated.Executes the closure whose matching predicate returns true -
getPredicates
Deprecated.Gets the predicates, do not modify the array.- Returns:
- the predicates
- Since:
- Commons Collections 3.1
-
getClosures
Deprecated.Gets the closures, do not modify the array.- Returns:
- the closures
- Since:
- Commons Collections 3.1
-
getDefaultClosure
Deprecated.Gets the default closure.- Returns:
- the default closure
- Since:
- Commons Collections 3.1
-