Top Description Fields Constructors Methods
org.apache.commons.collections4.functors

public Class WhileClosure<E>

extends Object
implements Closure<E>
Class Inheritance
All Implemented Interfaces
org.apache.commons.collections4.Closure
Imports
org.apache.commons.collections4.Closure, .Predicate

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

Warning

from v4.1 onwards this class will not be serializable anymore in order to prevent potential remote code execution exploits. Please refer to COLLECTIONS-580 for more details.

Since
3.0

Field Summary

Modifier and TypeField and Description
private final Closure<? super E>
iClosure

The closure to call

private final boolean
iDoLoop

The flag, true is a do loop, false is a while

private final Predicate<? super E>
iPredicate

The test condition

Constructor Summary

AccessConstructor and Description
public
WhileClosure(final Predicate<? super E>
the predicate used to evaluate when the loop terminates, not null
predicate
,
final Closure<? super E>
the closure the execute, not null
closure
,
final boolean
true to act as a do-while loop, always executing the closure once
doLoop
)

Constructor that performs no validation.

Method Summary

Modifier and TypeMethod and Description
public void
execute(final E
the input object
input
)

Implements org.apache.commons.collections4.Closure.execute.

Executes the closure until the predicate is false.
public Closure<? super E>

Returns:

the closure
getClosure
()

Gets the closure.

public Predicate<? super E>

Returns:

the predicate
getPredicate
()

Gets the predicate in use.

public boolean

Returns:

true is do-while, false if while
isDoLoop
()

Is the loop a do-while loop.

public static <
the type that the closure acts on
E
>
Closure<E>

Returns:

the while closure
whileClosure
(final Predicate<? super E>
the predicate used to evaluate when the loop terminates, not null
predicate
,
final Closure<? super E>
the closure the execute, not null
closure
,
final boolean
true to act as a do-while loop, always executing the closure once
doLoop
)

Factory method that performs validation.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

iClosureback to summary
private final Closure<? super E> iClosure

The closure to call

iDoLoopback to summary
private final boolean iDoLoop

The flag, true is a do loop, false is a while

iPredicateback to summary
private final Predicate<? super E> iPredicate

The test condition

Constructor Detail

WhileClosureback to summary
public WhileClosure(final Predicate<? super E> predicate, final Closure<? super E> closure, final boolean doLoop)

Constructor that performs no validation. Use whileClosure if you want that.

Parameters
predicate:Predicate<? super E>

the predicate used to evaluate when the loop terminates, not null

closure:Closure<? super E>

the closure the execute, not null

doLoop:boolean

true to act as a do-while loop, always executing the closure once

Method Detail

executeback to summary
public void execute(final E input)

Implements org.apache.commons.collections4.Closure.execute.

Executes the closure until the predicate is false.

Parameters
input:E

the input object

Annotations
@Override
getClosureback to summary
public Closure<? super E> getClosure()

Gets the closure.

Returns:Closure<? super E>

the closure

Since
3.1
getPredicateback to summary
public Predicate<? super E> getPredicate()

Gets the predicate in use.

Returns:Predicate<? super E>

the predicate

Since
3.1
isDoLoopback to summary
public boolean isDoLoop()

Is the loop a do-while loop.

Returns:boolean

true is do-while, false if while

Since
3.1
whileClosureback to summary
public static <E> Closure<E> whileClosure(final Predicate<? super E> predicate, final Closure<? super E> closure, final boolean doLoop)

Factory method that performs validation.

Parameters
<E>
the type that the closure acts on
predicate:Predicate<? super E>

the predicate used to evaluate when the loop terminates, not null

closure:Closure<? super E>

the closure the execute, not null

doLoop:boolean

true to act as a do-while loop, always executing the closure once

Returns:Closure<E>

the while closure

Exceptions
NullPointerException:
if the predicate or closure is null