Package org.apache.commons.math3.util
Class Incrementor
- java.lang.Object
-
- org.apache.commons.math3.util.Incrementor
-
@Deprecated public class Incrementor extends java.lang.ObjectDeprecated.UseIntegerSequence.Incrementorinstead.Utility that increments a counter until a maximum is reached, at which point, the instance will by default throw aMaxCountExceededException. However, the user is able to override this behaviour by defining a customcallback, in order to e.g. select which exception must be thrown.- Since:
- 3.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceIncrementor.MaxCountExceededCallbackDeprecated.Defines a method to be called at counter exhaustion.
-
Field Summary
Fields Modifier and Type Field Description private intcountDeprecated.Current count.private Incrementor.MaxCountExceededCallbackmaxCountCallbackDeprecated.Function called at counter exhaustion.private intmaximalCountDeprecated.Upper limit for the counter.
-
Constructor Summary
Constructors Constructor Description Incrementor()Deprecated.Default constructor.Incrementor(int max)Deprecated.Defines a maximal count.Incrementor(int max, Incrementor.MaxCountExceededCallback cb)Deprecated.Defines a maximal count and a callback method to be triggered at counter exhaustion.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleancanIncrement()Deprecated.Checks whether a single increment is allowed.intgetCount()Deprecated.Gets the current count.intgetMaximalCount()Deprecated.Gets the upper limit of the counter.voidincrementCount()Deprecated.Adds one to the current iteration count.voidincrementCount(int value)Deprecated.Performs multiple increments.voidresetCount()Deprecated.Resets the counter to 0.voidsetMaximalCount(int max)Deprecated.Sets the upper limit for the counter.static Incrementorwrap(IntegerSequence.Incrementor incrementor)Deprecated.Create an instance that delegates everything to aIntegerSequence.Incrementor.
-
-
-
Field Detail
-
maximalCount
private int maximalCount
Deprecated.Upper limit for the counter.
-
count
private int count
Deprecated.Current count.
-
maxCountCallback
private final Incrementor.MaxCountExceededCallback maxCountCallback
Deprecated.Function called at counter exhaustion.
-
-
Constructor Detail
-
Incrementor
public Incrementor()
Deprecated.Default constructor. For the new instance to be useful, the maximal count must be set by callingsetMaximalCount.
-
Incrementor
public Incrementor(int max)
Deprecated.Defines a maximal count.- Parameters:
max- Maximal count.
-
Incrementor
public Incrementor(int max, Incrementor.MaxCountExceededCallback cb) throws NullArgumentExceptionDeprecated.Defines a maximal count and a callback method to be triggered at counter exhaustion.- Parameters:
max- Maximal count.cb- Function to be called when the maximal count has been reached.- Throws:
NullArgumentException- ifcbisnull
-
-
Method Detail
-
setMaximalCount
public void setMaximalCount(int max)
Deprecated.Sets the upper limit for the counter. This does not automatically reset the current count to zero (seeresetCount()).- Parameters:
max- Upper limit of the counter.
-
getMaximalCount
public int getMaximalCount()
Deprecated.Gets the upper limit of the counter.- Returns:
- the counter upper limit.
-
getCount
public int getCount()
Deprecated.Gets the current count.- Returns:
- the current count.
-
canIncrement
public boolean canIncrement()
Deprecated.Checks whether a single increment is allowed.- Returns:
falseif the next call toincrementCountwill trigger aMaxCountExceededException,trueotherwise.
-
incrementCount
public void incrementCount(int value) throws MaxCountExceededExceptionDeprecated.Performs multiple increments. See the otherincrementCountmethod).- Parameters:
value- Number of increments.- Throws:
MaxCountExceededException- at counter exhaustion.
-
incrementCount
public void incrementCount() throws MaxCountExceededExceptionDeprecated.Adds one to the current iteration count. At counter exhaustion, this method will call thetriggermethod of the callback object passed to theconstructor. If not explictly set, a default callback is used that will throw aMaxCountExceededException.- Throws:
MaxCountExceededException- at counter exhaustion, unless a customcallbackhas been set at construction.
-
resetCount
public void resetCount()
Deprecated.Resets the counter to 0.
-
wrap
public static Incrementor wrap(IntegerSequence.Incrementor incrementor)
Deprecated.Create an instance that delegates everything to aIntegerSequence.Incrementor.This factory method is intended only as a temporary hack for internal use in Apache Commons Math 3.X series, when
Incrementoris required in interface (as a return value or in protected fields). It should not be used in other cases. TheIntegerSequence.Incrementorclass should be used instead ofIncrementor.All methods are mirrored to the underlying
IntegerSequence.Incrementor, as long as neithersetMaximalCount(int)norresetCount()are called. If one of these two methods is called, the created instance becomes independent of theIntegerSequence.Incrementorused at creation. The rationale is thatIntegerSequence.Incrementorcannot change their maximal count and cannot be reset.- Parameters:
incrementor- wrappedIntegerSequence.Incrementor- Returns:
- an incrementor wrapping an
IntegerSequence.Incrementor - Since:
- 3.6
-
-