⇒ Index (Frames) |  ⇒ Index (No Frames) |  ⇒ Package |  ⇒ Package Tree |  ⇒ Full Tree 
org.apache.commons.collections.functors

Class WhileClosure

java.lang.Object
|
+--org.apache.commons.collections.functors.WhileClosure

All Implemented Interfaces:
Closure, Serializable


public class WhileClosure
extends java.lang.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
Author:
Stephen Colebourne

Constructor Summary

WhileClosure(Predicate predicate, Closure closure, boolean doLoop)

Constructor that performs no validation.

Method Summary

void

execute(Object input)

Execute the closure until the predicate is false.

static Closure

getInstance(Predicate predicate, Closure closure, boolean doLoop)

Factory method that performs validation.

Constructor Details

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 Details

execute

public void execute(Object input)

Execute the closure until the predicate is false.

Parameters:
input

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:
- if the predicate or closure is null