org.apache.commons.collections.functors
Class IfClosure
- Closure, Serializable
Closure implementation acts as an if statement calling one or other closure
based on a predicate.
Version:
- Stephen Colebourne
- Commons Collections 3.0
IfClosure
public IfClosure(Predicate predicate,
Closure trueClosure,
Closure falseClosure)
Constructor that performs no validation.
Use getInstance
if you want that.
predicate
- predicate to switch on, not nulltrueClosure
- closure used if true, not nullfalseClosure
- closure used if false, not null
execute
public void execute(Object input)
Executes the true or false closure accoring to the result of the predicate.
- execute in interface Closure
input
- the input object
getFalseClosure
public Closure getFalseClosure()
Gets the closure called when false.
- the closure
- Commons Collections 3.1
getInstance
public static Closure getInstance(Predicate predicate,
Closure trueClosure,
Closure falseClosure)
Factory method that performs validation.
predicate
- predicate to switch ontrueClosure
- closure used if truefalseClosure
- closure used if false
- the
if
closure
getPredicate
public Predicate getPredicate()
Gets the predicate.
- the predicate
- Commons Collections 3.1
getTrueClosure
public Closure getTrueClosure()
Gets the closure called when true.
- the closure
- Commons Collections 3.1
Copyright © 2001-2005 Apache Software Foundation. All Rights Reserved.