|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.kano.joscar.SeqNum
Represents a sequence of numbers within a given range and allows for
automatically-wrapping sequential traversal of such a sequence. This class
has an internal value for the "current" value in the sequence, which is
advanced with each call to next()
.
Example usage:
class CommandSender { // command ID's must be between 1 and 100 and each // must be greater than the last, unless wrapping // back to 1 from 100 SeqNum cmdIdSeq = new SeqNum(1, 100); void sendCmd(Command cmd) { long cmdId = cmdIdSeq.next(); System.out.println("Command #" + cmdId + ": " + cmd); reallySendCmd(cmd); } ... }
Constructor Summary | |
SeqNum(long min,
long max)
Creates a new sequence with the given minimum and maximum values. |
|
SeqNum(long min,
long max,
long current)
Creates a new sequence with the given minimum and maximum values. |
Method Summary | |
long |
getLast()
Returns the last value returned by next() , or the initial value if
next() has not been called. |
long |
getMax()
Returns the maximum value of an element of this sequence. |
long |
getMin()
Returns the minimum value of an element of this sequence. |
long |
next()
Returns the next element of this sequence. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public SeqNum(long min, long max)
next
could be that value.
min
- the smallest value allowed in this sequencemax
- the largest value allowed in this sequencepublic SeqNum(long min, long max, long current)
next
could be that value.
min
- the smallest value allowed in this sequencemax
- the largest value allowed in this sequencecurrent
- an initial value for the current value in this sequence
java.lang.IllegalArgumentException
- if the given initial value does not lie
within the given rangeMethod Detail |
public final long getMin()
public final long getMax()
public final long getLast()
next()
, or the initial value if
next()
has not been called.
next()
public long next()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |