org.apache.commons.collections.functors
Class IfClosure<T>

java.lang.Object
  extended by org.apache.commons.collections.functors.IfClosure<T>
All Implemented Interfaces:
Serializable, Closure<T>

public class IfClosure<T>
extends Object
implements Closure<T>, Serializable

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

Since:
Commons Collections 3.0
Version:
$Revision: 1.1.1.1 $ $Date: 2005/05/23 04:34:23 $
Author:
Matt Hall, John Watkinson, Stephen Colebourne
See Also:
Serialized Form

Constructor Summary
IfClosure(Predicate<? super T> predicate, Closure<? super T> trueClosure, Closure<? super T> falseClosure)
          Constructor that performs no validation.
 
Method Summary
 void execute(T input)
          Executes the true or false closure accoring to the result of the predicate.
 Closure<? super T> getFalseClosure()
          Gets the closure called when false.
static
<T> Closure<T>
getInstance(Predicate<? super T> predicate, Closure<? super T> trueClosure, Closure<? super T> falseClosure)
          Factory method that performs validation.
 Predicate<? super T> getPredicate()
          Gets the predicate.
 Closure<? super T> getTrueClosure()
          Gets the closure called when true.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IfClosure

public IfClosure(Predicate<? super T> predicate,
                 Closure<? super T> trueClosure,
                 Closure<? super T> falseClosure)
Constructor that performs no validation. Use getInstance if 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 Detail

getInstance

public static <T> Closure<T> getInstance(Predicate<? super T> predicate,
                                         Closure<? super T> trueClosure,
                                         Closure<? super T> falseClosure)
Factory method that performs validation.

Parameters:
predicate - predicate to switch on
trueClosure - closure used if true
falseClosure - closure used if false
Returns:
the if closure
Throws:
IllegalArgumentException - if any argument is null

execute

public void execute(T input)
Executes the true or false closure accoring to the result of the predicate.

Specified by:
execute in interface Closure<T>
Parameters:
input - the input object

getPredicate

public Predicate<? super T> getPredicate()
Gets the predicate.

Returns:
the predicate
Since:
Commons Collections 3.1

getTrueClosure

public Closure<? super T> getTrueClosure()
Gets the closure called when true.

Returns:
the closure
Since:
Commons Collections 3.1

getFalseClosure

public Closure<? super T> getFalseClosure()
Gets the closure called when false.

Returns:
the closure
Since:
Commons Collections 3.1


Copyright © 2005-2005 Apache Software Foundation, Matt Hall, John Watkinson. All Rights Reserved.