Class IfClosure<T>
java.lang.Object
org.apache.commons.collections4.functors.IfClosure<T>
- Type Parameters:
- T- the type of the input to the operation.
- All Implemented Interfaces:
- Serializable,- Consumer<T>,- Closure<T>
Closure implementation acts as an if statement calling one or other closure
 based on a predicate.
- Since:
- 3.0
- See Also:
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidExecutes 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.
- 
Constructor Details- 
IfClosureConstructor that performs no validation. UseifClosureif you want that.This constructor creates a closure that performs no action when the predicate is false. - Parameters:
- predicate- predicate to switch on, not null
- trueClosure- closure used if true, not null
- Since:
- 3.2
 
- 
IfClosurepublic IfClosure(Predicate<? super T> predicate, Closure<? super T> trueClosure, Closure<? super T> falseClosure) Constructor that performs no validation. UseifClosureif you want that.- Parameters:
- predicate- predicate to switch on, not null
- trueClosure- closure used if true, not null
- falseClosure- closure used if false, not null
 
 
- 
- 
Method Details- 
ifClosurepublic 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 on
- trueClosure- closure used if true
- Returns:
- the ifclosure
- Throws:
- NullPointerException- if either argument is null
- Since:
- 3.2
 
- 
ifClosurepublic 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 on
- trueClosure- closure used if true
- falseClosure- closure used if false
- Returns:
- the ifclosure
- Throws:
- NullPointerException- if any argument is null
 
- 
execute
- 
getFalseClosureGets the closure called when false.- Returns:
- the closure
- Since:
- 3.1
 
- 
getPredicate
- 
getTrueClosureGets the closure called when true.- Returns:
- the closure
- Since:
- 3.1
 
 
-