Class IfClosure
java.lang.Object
org.apache.commons.collections.functors.IfClosure
- All Implemented Interfaces:
Serializable
,Closure
Closure implementation acts as an if statement calling one or other closure
based on a predicate.
- Since:
- Commons Collections 3.0
- Version:
- $Revision: 646777 $ $Date: 2008-04-10 14:33:15 +0200 (Thu, 10 Apr 2008) $
- Author:
- Stephen Colebourne, Matt Benson
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Executes the true or false closure accoring to the result of the predicate.Gets the closure called when false.static Closure
getInstance
(Predicate predicate, Closure trueClosure) Factory method that performs validation.static Closure
getInstance
(Predicate predicate, Closure trueClosure, Closure falseClosure) Factory method that performs validation.Gets the predicate.Gets the closure called when true.
-
Constructor Details
-
IfClosure
Constructor that performs no validation. UsegetInstance
if you want that.This constructor creates a closure that performs no action when the predicate is false.
- Parameters:
predicate
- predicate to switch on, not nulltrueClosure
- closure used if true, not null- Since:
- Commons Collections 3.2
-
IfClosure
Constructor that performs no validation. UsegetInstance
if you want that.- Parameters:
predicate
- predicate to switch on, not nulltrueClosure
- closure used if true, not nullfalseClosure
- closure used if false, not null
-
-
Method Details
-
getInstance
Factory method that performs validation.This factory creates a closure that performs no action when the predicate is false.
- Parameters:
predicate
- predicate to switch ontrueClosure
- closure used if true- Returns:
- the
if
closure - Throws:
IllegalArgumentException
- if either argument is null- Since:
- Commons Collections 3.2
-
getInstance
Factory method that performs validation.- Parameters:
predicate
- predicate to switch ontrueClosure
- closure used if truefalseClosure
- closure used if false- Returns:
- the
if
closure - Throws:
IllegalArgumentException
- if any argument is null
-
execute
Executes the true or false closure accoring to the result of the predicate. -
getPredicate
Gets the predicate.- Returns:
- the predicate
- Since:
- Commons Collections 3.1
-
getTrueClosure
Gets the closure called when true.- Returns:
- the closure
- Since:
- Commons Collections 3.1
-
getFalseClosure
Gets the closure called when false.- Returns:
- the closure
- Since:
- Commons Collections 3.1
-