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

public Class ForClosure<E>

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

Closure implementation that calls another closure n times, like a for 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 int
iCount

The number of times to loop

Constructor Summary

AccessConstructor and Description
public
ForClosure(final int
the number of times to execute the closure
count
,
final Closure<? super E>
the closure to execute, not null
closure
)

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 count times.
public static <
the type that the closure acts on
E
>
Closure<E>

Returns:

the for closure
forClosure
(final int
the number of times to execute the closure
count
,
final Closure<? super E>
the closure to execute, not null
closure
)

Factory method that performs validation.

public Closure<? super E>

Returns:

the closure
getClosure
()

Gets the closure.

public int

Returns:

the count
getCount
()

Gets the count.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

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

The closure to call

iCountback to summary
private final int iCount

The number of times to loop

Constructor Detail

ForClosureback to summary
public ForClosure(final int count, final Closure<? super E> closure)

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

Parameters
count:int

the number of times to execute the closure

closure:Closure<? super E>

the closure to execute, not null

Method Detail

executeback to summary
public void execute(final E input)

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

Executes the closure count times.

Parameters
input:E

the input object

Annotations
@Override
forClosureback to summary
public static <E> Closure<E> forClosure(final int count, final 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.

Parameters
<E>
the type that the closure acts on
count:int

the number of times to execute the closure

closure:Closure<? super E>

the closure to execute, not null

Returns:Closure<E>

the for closure

Annotations
@SuppressWarnings:unchecked
getClosureback to summary
public Closure<? super E> getClosure()

Gets the closure.

Returns:Closure<? super E>

the closure

Since
3.1
getCountback to summary
public int getCount()

Gets the count.

Returns:int

the count

Since
3.1