Top Description Inners Fields Constructors Methods
org.apache.commons.math3.util

public Class Incrementor

extends Object
Class Inheritance
Annotations
@Deprecated
Imports
org.apache.commons.math3.exception.MaxCountExceededException, .NullArgumentException

Deprecated

Use IntegerSequence.Incrementor instead.

Utility that increments a counter until a maximum is reached, at which point, the instance will by default throw a MaxCountExceededException. However, the user is able to override this behaviour by defining a custom callback, in order to e.g. select which exception must be thrown.
Since
3.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
Incrementor.MaxCountExceededCallback

Defines a method to be called at counter exhaustion.

Field Summary

Modifier and TypeField and Description
private int
count

Current count.

private final Incrementor.MaxCountExceededCallback
maxCountCallback

Function called at counter exhaustion.

private int
maximalCount

Upper limit for the counter.

Constructor Summary

AccessConstructor and Description
public
Incrementor()

Default constructor.

public
Incrementor(int
Maximal count.
max
)

Defines a maximal count.

public
Incrementor(int
Maximal count.
max
,
Incrementor.MaxCountExceededCallback
Function to be called when the maximal count has been reached.
cb
)

Defines a maximal count and a callback method to be triggered at counter exhaustion.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

false if the next call to incrementCount will trigger a MaxCountExceededException, true otherwise.
canIncrement
()

Checks whether a single increment is allowed.

public int

Returns:

the current count.
getCount
()

Gets the current count.

public int

Returns:

the counter upper limit.
getMaximalCount
()

Gets the upper limit of the counter.

public void
incrementCount(int
Number of increments.
value
)

Performs multiple increments.

public void
incrementCount()

Adds one to the current iteration count.

public void
resetCount()

Resets the counter to 0.

public void
setMaximalCount(int
Upper limit of the counter.
max
)

Sets the upper limit for the counter.

public static Incrementor

Returns:

an incrementor wrapping an IntegerSequence.Incrementor
wrap
(final IntegerSequence.Incrementor incrementor)
Deprecated as a consequence of Incrementor being deprecated.

Create an instance that delegates everything to a IntegerSequence.Incrementor.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

countback to summary
private int count

Current count.

maxCountCallbackback to summary
private final Incrementor.MaxCountExceededCallback maxCountCallback

Function called at counter exhaustion.

maximalCountback to summary
private int maximalCount

Upper limit for the counter.

Constructor Detail

Incrementorback to summary
public Incrementor()

Default constructor. For the new instance to be useful, the maximal count must be set by calling setMaximalCount.

Incrementorback to summary
public Incrementor(int max)

Defines a maximal count.

Parameters
max:int

Maximal count.

Incrementorback to summary
public Incrementor(int max, Incrementor.MaxCountExceededCallback cb) throws NullArgumentException

Defines a maximal count and a callback method to be triggered at counter exhaustion.

Parameters
max:int

Maximal count.

cb:Incrementor.MaxCountExceededCallback

Function to be called when the maximal count has been reached.

Exceptions
NullArgumentException:
if cb is null

Method Detail

canIncrementback to summary
public boolean canIncrement()

Checks whether a single increment is allowed.

Returns:boolean

false if the next call to incrementCount will trigger a MaxCountExceededException, true otherwise.

getCountback to summary
public int getCount()

Gets the current count.

Returns:int

the current count.

getMaximalCountback to summary
public int getMaximalCount()

Gets the upper limit of the counter.

Returns:int

the counter upper limit.

incrementCountback to summary
public void incrementCount(int value) throws MaxCountExceededException

Performs multiple increments. See the other incrementCount method).

Parameters
value:int

Number of increments.

Exceptions
MaxCountExceededException:
at counter exhaustion.
incrementCountback to summary
public void incrementCount() throws MaxCountExceededException

Adds one to the current iteration count. At counter exhaustion, this method will call the trigger method of the callback object passed to the constructor. If not explictly set, a default callback is used that will throw a MaxCountExceededException.

Exceptions
MaxCountExceededException:
at counter exhaustion, unless a custom callback has been set at construction.
resetCountback to summary
public void resetCount()

Resets the counter to 0.

setMaximalCountback to summary
public void setMaximalCount(int max)

Sets the upper limit for the counter. This does not automatically reset the current count to zero (see resetCount()).

Parameters
max:int

Upper limit of the counter.

wrapback to summary
public static Incrementor wrap(final IntegerSequence.Incrementor incrementor)

Deprecated

as a consequence of Incrementor being deprecated. See corresponding docs for further information.

Create an instance that delegates everything to a IntegerSequence.Incrementor.

This factory method is intended only as a temporary hack for internal use in Apache Commons Math 3.X series, when Incrementor is required in interface (as a return value or in protected fields). It should not be used in other cases. The IntegerSequence.Incrementor class should be used instead of Incrementor.

All methods are mirrored to the underlying IntegerSequence.Incrementor, as long as neither setMaximalCount(int) nor resetCount() are called. If one of these two methods is called, the created instance becomes independent of the IntegerSequence.Incrementor used at creation. The rationale is that IntegerSequence.Incrementor cannot change their maximal count and cannot be reset.

Parameters
incrementor:IntegerSequence.Incrementor

wrapped IntegerSequence.Incrementor

Returns:Incrementor

an incrementor wrapping an IntegerSequence.Incrementor

Since
3.6
org.apache.commons.math3.util back to summary

public Interface Incrementor.MaxCountExceededCallback

Known Direct Implementers
org.apache.commons.math3.optim.AbstractOptimizationProblem.MaxEvalCallback, org.apache.commons.math3.optim.AbstractOptimizationProblem.MaxIterCallback, org.apache.commons.math3.optim.BaseOptimizer.MaxEvalCallback, org.apache.commons.math3.optim.BaseOptimizer.MaxIterCallback

Defines a method to be called at counter exhaustion. The trigger method should usually throw an exception.

Method Summary

Modifier and TypeMethod and Description
public void
trigger(int
Maximal count.
maximalCount
)

Function called when the maximal count has been reached.

Method Detail

triggerback to summary
public void trigger(int maximalCount) throws MaxCountExceededException

Function called when the maximal count has been reached.

Parameters
maximalCount:int

Maximal count.

Exceptions
MaxCountExceededException:
at counter exhaustion