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

public Class IfTransformer<I, O>

extends Object
implements Transformer<I, O>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, org.apache.commons.collections4.Transformer
Type Parameters
<I>
The input type for the transformer
<O>
The output type for the transformer
Imports
java.io.Serializable, org.apache.commons.collections4.Predicate, .Transformer

Transformer implementation that will call one of two closures based on whether a predicate evaluates as true or false.
Since
4.1

Field Summary

Modifier and TypeField and Description
private final Transformer<? super I, ? extends O>
iFalseTransformer

The transformer to use if false

private final Predicate<? super I>
iPredicate

The test

private final Transformer<? super I, ? extends O>
iTrueTransformer

The transformer to use if true

private static final long
serialVersionUID

Serial version UID

Constructor Summary

AccessConstructor and Description
public
IfTransformer(final Predicate<? super I>
predicate to switch on, not null
predicate
,
final Transformer<? super I, ? extends O>
transformer used if true, not null
trueTransformer
,
final Transformer<? super I, ? extends O>
transformer used if false, not null
falseTransformer
)

Constructor that performs no validation.

Method Summary

Modifier and TypeMethod and Description
public Transformer<? super I, ? extends O>

Returns:

the transformer
getFalseTransformer
()

Gets the transformer used when false.

public Predicate<? super I>

Returns:

the predicate
getPredicate
()

Gets the predicate.

public Transformer<? super I, ? extends O>

Returns:

the transformer
getTrueTransformer
()

Gets the transformer used when true.

public static <
input type for the transformer
I
,
output type for the transformer
O
>
Transformer<I, O>

Returns:

the if transformer
ifTransformer
(final Predicate<? super I>
predicate to switch on
predicate
,
final Transformer<? super I, ? extends O>
transformer used if true
trueTransformer
,
final Transformer<? super I, ? extends O>
transformer used if false
falseTransformer
)

Factory method that performs validation.

public static <
input and output type for the transformer
T
>
Transformer<T, T>

Returns:

the if transformer
ifTransformer
(final Predicate<? super T>
predicate to switch on
predicate
,
final Transformer<? super T, ? extends T>
transformer used if true
trueTransformer
)

Factory method that performs validation.

public O

Returns:

the transformed result
transform
(final I
the input object to transform
input
)

Implements org.apache.commons.collections4.Transformer.transform.

Transforms the input using the true or false transformer based to the result of the predicate.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

iFalseTransformerback to summary
private final Transformer<? super I, ? extends O> iFalseTransformer

The transformer to use if false

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

The test

iTrueTransformerback to summary
private final Transformer<? super I, ? extends O> iTrueTransformer

The transformer to use if true

serialVersionUIDback to summary
private static final long serialVersionUID

Serial version UID

Constructor Detail

IfTransformerback to summary
public IfTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer)

Constructor that performs no validation. Use the static factory method ifTransformer if you want that.

Parameters
predicate:Predicate<? super I>

predicate to switch on, not null

trueTransformer:Transformer<? super I, ? extends O>

transformer used if true, not null

falseTransformer:Transformer<? super I, ? extends O>

transformer used if false, not null

Method Detail

getFalseTransformerback to summary
public Transformer<? super I, ? extends O> getFalseTransformer()

Gets the transformer used when false.

Returns:Transformer<? super I, ? extends O>

the transformer

getPredicateback to summary
public Predicate<? super I> getPredicate()

Gets the predicate.

Returns:Predicate<? super I>

the predicate

getTrueTransformerback to summary
public Transformer<? super I, ? extends O> getTrueTransformer()

Gets the transformer used when true.

Returns:Transformer<? super I, ? extends O>

the transformer

ifTransformerback to summary
public static <I, O> Transformer<I, O> ifTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer)

Factory method that performs validation.

Parameters
<I>
input type for the transformer
<O>
output type for the transformer
predicate:Predicate<? super I>

predicate to switch on

trueTransformer:Transformer<? super I, ? extends O>

transformer used if true

falseTransformer:Transformer<? super I, ? extends O>

transformer used if false

Returns:Transformer<I, O>

the if transformer

Exceptions
NullPointerException:
if either argument is null
ifTransformerback to summary
public static <T> Transformer<T, T> ifTransformer(final Predicate<? super T> predicate, final Transformer<? super T, ? extends T> trueTransformer)

Factory method that performs validation.

This factory creates a transformer that just returns the input object when the predicate is false.

Parameters
<T>
input and output type for the transformer
predicate:Predicate<? super T>

predicate to switch on

trueTransformer:Transformer<? super T, ? extends T>

transformer used if true

Returns:Transformer<T, T>

the if transformer

Exceptions
NullPointerException:
if either argument is null
transformback to summary
public O transform(final I input)

Implements org.apache.commons.collections4.Transformer.transform.

Transforms the input using the true or false transformer based to the result of the predicate.

Parameters
input:I

the input object to transform

Returns:O

the transformed result

Annotations
@Override