public class Incrementor extends Object
MathIllegalStateException.
 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.| Modifier and Type | Class and Description | 
|---|---|
static interface  | 
Incrementor.MaxCountExceededCallback
Defines a method to be called at counter exhaustion. 
 | 
| Constructor and Description | 
|---|
Incrementor()
Creates an Incrementor. 
 | 
Incrementor(int max)
Creates an Incrementor. 
 | 
Incrementor(int max,
           Incrementor.MaxCountExceededCallback cb)
Creates an Incrementor. 
 | 
| Modifier and Type | Method and Description | 
|---|---|
boolean | 
canIncrement()
Checks whether incrementing the counter  
nTimes is allowed. | 
boolean | 
canIncrement(int nTimes)
Checks whether incrementing the counter several times is allowed. 
 | 
int | 
getCount()
Gets the current count. 
 | 
int | 
getMaximalCount()
Gets the upper limit of the counter. 
 | 
void | 
increment()
Adds the increment value to the current iteration count. 
 | 
void | 
increment(int nTimes)
Performs multiple increments. 
 | 
void | 
reset()
Resets the counter to 0. 
 | 
Incrementor | 
withCallback(Incrementor.MaxCountExceededCallback cb)
Creates a new instance with a given callback. 
 | 
Incrementor | 
withCount(int value)
Creates a new instance and set the counter to the given value. 
 | 
Incrementor | 
withMaximalCount(int max)
Creates a new instance with a given maximal count. 
 | 
public Incrementor()
 The maximal value will be set to Integer.MAX_VALUE.
public Incrementor(int max)
max - Maximal count.MathIllegalArgumentException - if max is negative.public Incrementor(int max,
                   Incrementor.MaxCountExceededCallback cb)
            throws NullArgumentException
max - Maximal count.cb - Function to be called when the maximal count has been reached.NullArgumentException - if cb is null.MathIllegalArgumentException - if max is negative.public Incrementor withCount(int value)
value - Value of the counter.public Incrementor withMaximalCount(int max)
max - Maximal count.MathIllegalArgumentException - if max is negative.public Incrementor withCallback(Incrementor.MaxCountExceededCallback cb)
cb - Callback to be called at counter exhaustion.public int getMaximalCount()
public int getCount()
public boolean canIncrement()
nTimes is allowed.false if calling increment()
 will trigger a MathIllegalStateException,
 true otherwise.public boolean canIncrement(int nTimes)
nTimes - Number of increments.false if calling increment(nTimes) would call the callback
 true otherwise.MathIllegalArgumentException - if nTimes is negative.public void increment(int nTimes)
nTimes - Number of increments.MathIllegalArgumentException - if nTimes is negative.increment()public void increment()
trigger method of the
 callback object passed to the
 withCallback(MaxCountExceededCallback) method.increment(int)public void reset()
Copyright © 2016-2021 CS GROUP. All rights reserved.