Top Description Fields Constructors Methods
org.apache.commons.collections4.functors

public Class IfClosure<E>

extends Object
implements Closure<E>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, org.apache.commons.collections4.Closure
Imports
java.io.Serializable, org.apache.commons.collections4.Closure, .Predicate

Closure implementation acts as an if statement calling one or other closure based on a predicate.
Since
3.0

Field Summary

Modifier and TypeField and Description
private final Closure<? super E>
iFalseClosure

The closure to use if false

private final Predicate<? super E>
iPredicate

The test

private final Closure<? super E>
iTrueClosure

The closure to use if true

private static final long
serialVersionUID

Serial version UID

Constructor Summary

AccessConstructor and Description
public
IfClosure(final Predicate<? super E>
predicate to switch on, not null
predicate
,
final Closure<? super E>
closure used if true, not null
trueClosure
)

Constructor that performs no validation.

public
IfClosure(final Predicate<? super E>
predicate to switch on, not null
predicate
,
final Closure<? super E>
closure used if true, not null
trueClosure
,
final Closure<? super E>
closure used if false, not null
falseClosure
)

Constructor that performs no validation.

Method Summary

Modifier and TypeMethod and Description
public void
execute(final E
the input object
input
)

Implements org.apache.commons.collections4.Closure.execute.

Executes the true or false closure according to the result of the predicate.
public Closure<? super E>

Returns:

the closure
getFalseClosure
()

Gets the closure called when false.

public Predicate<? super E>

Returns:

the predicate
getPredicate
()

Gets the predicate.

public Closure<? super E>

Returns:

the closure
getTrueClosure
()

Gets the closure called when true.

public static <
the type that the closure acts on
E
>
Closure<E>

Returns:

the if closure
ifClosure
(final Predicate<? super E>
predicate to switch on
predicate
,
final Closure<? super E>
closure used if true
trueClosure
)

Factory method that performs validation.

public static <
the type that the closure acts on
E
>
Closure<E>

Returns:

the if closure
ifClosure
(final Predicate<? super E>
predicate to switch on
predicate
,
final Closure<? super E>
closure used if true
trueClosure
,
final Closure<? super E>
closure used if false
falseClosure
)

Factory method that performs validation.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

iFalseClosureback to summary
private final Closure<? super E> iFalseClosure

The closure to use if false

iPredicateback to summary
private final Predicate<? super E> iPredicate

The test

iTrueClosureback to summary
private final Closure<? super E> iTrueClosure

The closure to use if true

serialVersionUIDback to summary
private static final long serialVersionUID

Serial version UID

Constructor Detail

IfClosureback to summary
public IfClosure(final Predicate<? super E> predicate, final Closure<? super E> trueClosure)

Constructor that performs no validation. Use ifClosure if you want that.

This constructor creates a closure that performs no action when the predicate is false.

Parameters
predicate:Predicate<? super E>

predicate to switch on, not null

trueClosure:Closure<? super E>

closure used if true, not null

Since
3.2
IfClosureback to summary
public IfClosure(final Predicate<? super E> predicate, final Closure<? super E> trueClosure, final Closure<? super E> falseClosure)

Constructor that performs no validation. Use ifClosure if you want that.

Parameters
predicate:Predicate<? super E>

predicate to switch on, not null

trueClosure:Closure<? super E>

closure used if true, not null

falseClosure:Closure<? super E>

closure used if false, not null

Method Detail

executeback to summary
public void execute(final E input)

Implements org.apache.commons.collections4.Closure.execute.

Executes the true or false closure according to the result of the predicate.

Parameters
input:E

the input object

Annotations
@Override
getFalseClosureback to summary
public Closure<? super E> getFalseClosure()

Gets the closure called when false.

Returns:Closure<? super E>

the closure

Since
3.1
getPredicateback to summary
public Predicate<? super E> getPredicate()

Gets the predicate.

Returns:Predicate<? super E>

the predicate

Since
3.1
getTrueClosureback to summary
public Closure<? super E> getTrueClosure()

Gets the closure called when true.

Returns:Closure<? super E>

the closure

Since
3.1
ifClosureback to summary
public static <E> Closure<E> ifClosure(final Predicate<? super E> predicate, final Closure<? super E> trueClosure)

Factory method that performs validation.

This factory creates a closure that performs no action when the predicate is false.

Parameters
<E>
the type that the closure acts on
predicate:Predicate<? super E>

predicate to switch on

trueClosure:Closure<? super E>

closure used if true

Returns:Closure<E>

the if closure

Exceptions
NullPointerException:
if either argument is null
Since
3.2
ifClosureback to summary
public static <E> Closure<E> ifClosure(final Predicate<? super E> predicate, final Closure<? super E> trueClosure, final Closure<? super E> falseClosure)

Factory method that performs validation.

Parameters
<E>
the type that the closure acts on
predicate:Predicate<? super E>

predicate to switch on

trueClosure:Closure<? super E>

closure used if true

falseClosure:Closure<? super E>

closure used if false

Returns:Closure<E>

the if closure

Exceptions
NullPointerException:
if any argument is null