Class IfClosure<E>
java.lang.Object
org.apache.commons.collections4.functors.IfClosure<E>
- All Implemented Interfaces:
Serializable
,Closure<E>
Closure implementation acts as an if statement calling one or other closure
based on a predicate.
- Since:
- 3.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionThe closure to use if falseThe testThe closure to use if trueprivate static final long
Serial version UID -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Executes the true or false closure according to the result of the predicate.Gets the closure called when false.Gets the predicate.Gets the closure called when true.static <E> Closure
<E> Factory method that performs validation.static <E> Closure
<E> ifClosure
(Predicate<? super E> predicate, Closure<? super E> trueClosure, Closure<? super E> falseClosure) Factory method that performs validation.
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDSerial version UID- See Also:
-
iPredicate
The test -
iTrueClosure
The closure to use if true -
iFalseClosure
The closure to use if false
-
-
Constructor Details
-
IfClosure
Constructor that performs no validation. UseifClosure
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:
- 3.2
-
IfClosure
public IfClosure(Predicate<? super E> predicate, Closure<? super E> trueClosure, Closure<? super E> falseClosure) Constructor that performs no validation. UseifClosure
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
-
ifClosure
public static <E> Closure<E> ifClosure(Predicate<? super E> predicate, Closure<? super E> trueClosure) Factory method that performs validation.This factory creates a closure that performs no action when the predicate is false.
- Type Parameters:
E
- the type that the closure acts on- Parameters:
predicate
- predicate to switch ontrueClosure
- closure used if true- Returns:
- the
if
closure - Throws:
NullPointerException
- if either argument is null- Since:
- 3.2
-
ifClosure
public static <E> Closure<E> ifClosure(Predicate<? super E> predicate, Closure<? super E> trueClosure, Closure<? super E> falseClosure) Factory method that performs validation.- Type Parameters:
E
- the type that the closure acts on- Parameters:
predicate
- predicate to switch ontrueClosure
- closure used if truefalseClosure
- closure used if false- Returns:
- the
if
closure - Throws:
NullPointerException
- if any argument is null
-
execute
Executes the true or false closure according to the result of the predicate. -
getPredicate
Gets the predicate.- Returns:
- the predicate
- Since:
- 3.1
-
getTrueClosure
Gets the closure called when true.- Returns:
- the closure
- Since:
- 3.1
-
getFalseClosure
Gets the closure called when false.- Returns:
- the closure
- Since:
- 3.1
-