org.apache.commons.collections4.functors

## Class WhileClosure<E>

- java.lang.Object
- - org.apache.commons.collections4.functors.WhileClosure<E>

- All Implemented Interfaces:
    Closure<E>

      public class WhileClosure<E>
      extends Object
      implements Closure<E>

  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
  Version:
    $Id: WhileClosure.java 1714262 2015-11-13 20:08:45Z tn $

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `WhileClosure(Predicate<? super E> predicate, Closure<? super E> closure, boolean doLoop)` Constructor that performs no validation.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `execute(E input)` Executes the closure until the predicate is false.
    `Closure<? super E>` | `getClosure()` Gets the closure.
    `Predicate<? super E>` | `getPredicate()` Gets the predicate in use.
    `boolean` | `isDoLoop()` Is the loop a do-while loop.
    `static <E> Closure<E>` | `whileClosure(Predicate<? super E> predicate, Closure<? super E> closure, boolean doLoop)` Factory method that performs validation.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### WhileClosure

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

      Constructor that performs no validation. Use `whileClosure` 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

    - #### whileClosure

          public static <E> Closure<E> whileClosure(Predicate<? super E> predicate,
                                    Closure<? super E> closure,
                                    boolean doLoop)

      Factory method that performs validation.
      Type Parameters:
        `E` - the type that the closure acts on
      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:
        `NullPointerException` - if the predicate or closure is null

    - #### execute

          public void execute(E input)

      Executes the closure until the predicate is false.
      Specified by:
        `execute` in interface `Closure<E>`
      Parameters:
        `input` - the input object

    - #### getPredicate

          public Predicate<? super E> getPredicate()

      Gets the predicate in use.
      Returns:
        the predicate
      Since:
        3.1

    - #### getClosure

          public Closure<? super E> getClosure()

      Gets the closure.
      Returns:
        the closure
      Since:
        3.1

    - #### isDoLoop

          public boolean isDoLoop()

      Is the loop a do-while loop.
      Returns:
        true is do-while, false if while
      Since:
        3.1

Copyright © 2001–2015 The Apache Software Foundation. All rights reserved.