org.apache.commons.collections.functors

Class WhileClosure

public class WhileClosure extends Object implements Closure, 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: 348444 $ $Date: 2005-11-23 14:06:56 +0000 (Wed, 23 Nov 2005) $

Author: Stephen Colebourne

Constructor Summary
WhileClosure(Predicate predicate, Closure closure, boolean doLoop)
Constructor that performs no validation.
Method Summary
voidexecute(Object input)
Executes the closure until the predicate is false.
ClosuregetClosure()
Gets the closure.
static ClosuregetInstance(Predicate predicate, Closure closure, boolean doLoop)
Factory method that performs validation.
PredicategetPredicate()
Gets the predicate in use.
booleanisDoLoop()
Is the loop a do-while loop.

Constructor Detail

WhileClosure

public WhileClosure(Predicate predicate, Closure 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

execute

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

Parameters: input the input object

getClosure

public Closure getClosure()
Gets the closure.

Returns: the closure

Since: Commons Collections 3.1

getInstance

public static Closure getInstance(Predicate predicate, Closure 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

getPredicate

public Predicate getPredicate()
Gets the predicate in use.

Returns: the predicate

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 © 2001-2008 Apache Software Foundation. All Rights Reserved.