Class WhileClosure
- java.lang.Object
-
- org.apache.commons.collections.functors.WhileClosure
-
- All Implemented Interfaces:
java.io.Serializable
,Closure
public class WhileClosure extends java.lang.Object implements Closure, java.io.Serializable
Closure implementation that executes a closure repeatedly until a condition is met, like a do-while or while loop.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
- Since:
- Commons Collections 3.0
- Version:
- $Revision: 1713845 $ $Date: 2015-11-11 15:02:16 +0100 (Wed, 11 Nov 2015) $
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private Closure
iClosure
The closure to callprivate boolean
iDoLoop
The flag, true is a do loop, false is a whileprivate Predicate
iPredicate
The test conditionprivate static long
serialVersionUID
Serial version UID
-
Constructor Summary
Constructors Constructor Description WhileClosure(Predicate predicate, Closure closure, boolean doLoop)
Constructor that performs no validation.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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).
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
Serial version UID- See Also:
- Constant Field Values
-
iPredicate
private final Predicate iPredicate
The test condition
-
iClosure
private final Closure iClosure
The closure to call
-
iDoLoop
private final boolean iDoLoop
The flag, true is a do loop, false is a while
-
-
Constructor Detail
-
WhileClosure
public WhileClosure(Predicate predicate, Closure closure, boolean doLoop)
Constructor that performs no validation. UsegetInstance
if you want that.- Parameters:
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 once
-
-
Method Detail
-
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 nullclosure
- the closure the execute, not nulldoLoop
- true to act as a do-while loop, always executing the closure once- Returns:
- the
while
closure - Throws:
java.lang.IllegalArgumentException
- if the predicate or closure is null
-
execute
public void execute(java.lang.Object input)
Executes the closure until the predicate is false.
-
getPredicate
public Predicate getPredicate()
Gets the predicate in use.- Returns:
- the predicate
- Since:
- Commons Collections 3.1
-
getClosure
public Closure 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
-
writeObject
private void writeObject(java.io.ObjectOutputStream os) throws java.io.IOException
Overrides the default writeObject implementation to prevent serialization (see COLLECTIONS-580).- Throws:
java.io.IOException
-
readObject
private void readObject(java.io.ObjectInputStream is) throws java.lang.ClassNotFoundException, java.io.IOException
Overrides the default readObject implementation to prevent de-serialization (see COLLECTIONS-580).- Throws:
java.lang.ClassNotFoundException
java.io.IOException
-
-