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

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

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

Closure implementation that executes a closure repeatedly until a condition is met, like a do-while or while loop.

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

Constructor Summary
WhileClosure(Predicate<? super T> predicate, Closure<? super T> closure, boolean doLoop)
          Constructor that performs no validation.
 
Method Summary
 void execute(T input)
          Executes the closure until the predicate is false.
 Closure<? super T> getClosure()
          Gets the closure.
static
<T> Closure<T>
getInstance(Predicate<? super T> predicate, Closure<? super T> closure, boolean doLoop)
          Factory method that performs validation.
 Predicate<? super T> getPredicate()
          Gets the predicate in use.
 boolean isDoLoop()
          Is the loop a do-while loop.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WhileClosure

public WhileClosure(Predicate<? super T> predicate,
                    Closure<? super T> closure,
                    boolean doLoop)
Constructor that performs no validation. Use getInstance if you want that.

Parameters:
predicate - the predicate used to evaluate when the loop terminates, not null
closure - the closure the execute, not null
doLoop - true to act as a do-while loop, always executing the closure once
Method Detail

getInstance

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

Parameters:
predicate - the predicate used to evaluate when the loop terminates, not null
closure - the closure the execute, not null
doLoop - true to act as a do-while loop, always executing the closure once
Returns:
the while closure
Throws:
IllegalArgumentException - if the predicate or closure is null

execute

public void execute(T input)
Executes the closure until the predicate is false.

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

getPredicate

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

Returns:
the predicate
Since:
Commons Collections 3.1

getClosure

public Closure<? super T> getClosure()
Gets the closure.

Returns:
the closure
Since:
Commons Collections 3.1

isDoLoop

public boolean isDoLoop()
Is the loop a do-while loop.

Returns:
true is do-while, false if while
Since:
Commons Collections 3.1


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