public static class IntegerSequence.Incrementor extends Object implements Iterator<Integer>
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.Modifier and Type | Class and Description |
---|---|
static interface |
IntegerSequence.Incrementor.MaxCountExceededCallback
Defines a method to be called at counter exhaustion.
|
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.
|
static IntegerSequence.Incrementor |
create()
Factory method that creates a default instance.
|
int |
getCount()
Gets the current count.
|
int |
getMaximalCount()
Gets the upper limit of the counter.
|
boolean |
hasNext() |
void |
increment()
Adds the increment value to the current iteration count.
|
void |
increment(int nTimes)
Performs multiple increments.
|
Integer |
next() |
void |
remove()
Not applicable.
|
IntegerSequence.Incrementor |
withCallback(IntegerSequence.Incrementor.MaxCountExceededCallback cb)
Creates a new instance with a given callback.
|
IntegerSequence.Incrementor |
withIncrement(int step)
Creates a new instance with a given increment.
|
IntegerSequence.Incrementor |
withMaximalCount(int max)
Creates a new instance with a given maximal count.
|
IntegerSequence.Incrementor |
withStart(int start)
Creates a new instance with a given initial value.
|
public static IntegerSequence.Incrementor create()
withMaximalCount
.public IntegerSequence.Incrementor withStart(int start)
start
- Initial value of the counter.public IntegerSequence.Incrementor withMaximalCount(int max)
max
- Maximal count.public IntegerSequence.Incrementor withIncrement(int step)
step
- Increment.public IntegerSequence.Incrementor withCallback(IntegerSequence.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 MaxCountExceededException
,
true
otherwise.public boolean canIncrement(int nTimes)
nTimes
- Number of increments.false
if calling increment(nTimes)
would call the callback
true
otherwise.public void increment(int nTimes) throws MaxCountExceededException
nTimes
- Number of increments.MaxCountExceededException
- at counter exhaustion.NotStrictlyPositiveException
- if nTimes <= 0
.increment()
public void increment() throws MaxCountExceededException
trigger
method of the
callback object passed to the
withCallback(MaxCountExceededCallback)
method.
If not explicitly set, a default callback is used that will throw
a MaxCountExceededException
.MaxCountExceededException
- at counter exhaustion, unless a
custom callback
has been set.increment(int)
public void remove()
remove
in interface Iterator<Integer>
MathUnsupportedOperationException
Copyright © 2003–2016 The Apache Software Foundation. All rights reserved.