org.apache.commons.collections4.functors

## Class ForClosure<E>

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

- All Implemented Interfaces:
    Serializable, Closure<E>

      public class ForClosure<E>
      extends Object
      implements Closure<E>, Serializable

  Closure implementation that calls another closure n times, like a for loop.
  Since:
    3.0
  Version:
    $Id: ForClosure.java 1477798 2013-04-30 19:49:02Z tn $
  See Also:
    Serialized Form

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ForClosure(int count, Closure<? super E> closure)` Constructor that performs no validation.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `execute(E input)` Executes the closure `count` times.
    `static <E> Closure<E>` | `forClosure(int count, Closure<? super E> closure)` Factory method that performs validation.
    `Closure<? super E>` | `getClosure()` Gets the closure.
    `int` | `getCount()` Gets the count.

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

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

- - ### Constructor Detail

    - #### ForClosure

          public ForClosure(int count,
                    Closure<? super E> closure)

      Constructor that performs no validation. Use `forClosure` if you want that.
      Parameters:
        `count` - the number of times to execute the closure
        `closure` - the closure to execute, not null

  - ### Method Detail

    - #### forClosure

          public static <E> Closure<E> forClosure(int count,
                                  Closure<? super E> closure)

      Factory method that performs validation.

      A null closure or zero count returns the `NOPClosure`. A count of one returns the specified closure.

      Type Parameters:
        `E` - the type that the closure acts on
      Parameters:
        `count` - the number of times to execute the closure
        `closure` - the closure to execute, not null
      Returns:
        the `for` closure

    - #### execute

          public void execute(E input)

      Executes the closure `count` times.
      Specified by:
        `execute` in interface `Closure<E>`
      Parameters:
        `input` - the input object

    - #### getClosure

          public Closure<? super E> getClosure()

      Gets the closure.
      Returns:
        the closure
      Since:
        3.1

    - #### getCount

          public int getCount()

      Gets the count.
      Returns:
        the count
      Since:
        3.1

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