public class WhileClosure extends java.lang.Object implements Closure, java.io.Serializable
WARNING: from v3.2.2 onwards this class will throw an
UnsupportedOperationException
when trying to serialize or
de-serialize an instance to prevent potential remote code execution exploits.
In order to re-enable serialization support for WhileClosure
the following system property can be used (via -Dproperty=true):
org.apache.commons.collections.enableUnsafeSerialization
Modifier and Type | Field and Description |
---|---|
private Closure |
iClosure
The closure to call
|
private boolean |
iDoLoop
The flag, true is a do loop, false is a while
|
private Predicate |
iPredicate
The test condition
|
private static long |
serialVersionUID
Serial version UID
|
Constructor and Description |
---|
WhileClosure(Predicate predicate,
Closure closure,
boolean doLoop)
Constructor that performs no validation.
|
Modifier and Type | Method and Description |
---|---|
void |
execute(java.lang.Object input)
Executes the closure until the predicate is false.
|
Closure |
getClosure()
Gets the closure.
|
static Closure |
getInstance(Predicate predicate,
Closure closure,
boolean doLoop)
Factory method that performs validation.
|
Predicate |
getPredicate()
Gets the predicate in use.
|
boolean |
isDoLoop()
Is the loop a do-while loop.
|
private void |
readObject(java.io.ObjectInputStream is)
Overrides the default readObject implementation to prevent
de-serialization (see COLLECTIONS-580).
|
private void |
writeObject(java.io.ObjectOutputStream os)
Overrides the default writeObject implementation to prevent
serialization (see COLLECTIONS-580).
|
private static final long serialVersionUID
private final Predicate iPredicate
private final Closure iClosure
private final boolean iDoLoop
public WhileClosure(Predicate predicate, Closure closure, boolean doLoop)
getInstance
if you want that.predicate
- the predicate used to evaluate when the loop terminates, not nullclosure
- the closure the execute, not nulldoLoop
- true to act as a do-while loop, always executing the closure oncepublic static Closure getInstance(Predicate predicate, Closure closure, boolean doLoop)
predicate
- the predicate used to evaluate when the loop terminates, not nullclosure
- the closure the execute, not nulldoLoop
- true to act as a do-while loop, always executing the closure oncewhile
closurejava.lang.IllegalArgumentException
- if the predicate or closure is nullpublic void execute(java.lang.Object input)
public Predicate getPredicate()
public Closure getClosure()
public boolean isDoLoop()
private void writeObject(java.io.ObjectOutputStream os) throws java.io.IOException
java.io.IOException
private void readObject(java.io.ObjectInputStream is) throws java.lang.ClassNotFoundException, java.io.IOException
java.lang.ClassNotFoundException
java.io.IOException