Package com.storedobject.common
Class Sequencer
java.lang.Object
java.lang.Number
java.util.concurrent.atomic.AtomicLong
com.storedobject.common.Sequencer
- All Implemented Interfaces:
Serializable
The Sequencer class extends AtomicLong to provide functionality
for generating sequential numbers starting from a specified value.
It ensures the sequence resets to 1 if the current value reaches Long.MAX_VALUE.
- Author:
- Syam
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Methods inherited from class java.util.concurrent.atomic.AtomicLong
accumulateAndGet, addAndGet, compareAndExchange, compareAndExchangeAcquire, compareAndExchangeRelease, compareAndSet, decrementAndGet, doubleValue, floatValue, get, getAcquire, getAndAccumulate, getAndAdd, getAndDecrement, getAndIncrement, getAndSet, getAndUpdate, getOpaque, getPlain, incrementAndGet, intValue, lazySet, longValue, set, setOpaque, setPlain, setRelease, toString, updateAndGet, weakCompareAndSet, weakCompareAndSetAcquire, weakCompareAndSetPlain, weakCompareAndSetRelease, weakCompareAndSetVolatileMethods inherited from class java.lang.Number
byteValue, shortValue
-
Constructor Details
-
Sequencer
public Sequencer()Constructs a new Sequencer instance with the sequence starting at 1. This constructor invokes the parameterized constructor with the default starting value of 1. -
Sequencer
public Sequencer(long startingNumber) Constructs a new Sequencer instance with the sequence starting at the specified value.- Parameters:
startingNumber- the initial value from which the sequence will start
-
-
Method Details
-
current
public long current()Retrieves the current value of the sequencer without incrementing it. The value represents the latest number in the sequence.- Returns:
- the current value of the sequence
-
next
public long next()Generates the next number in the sequence. If the current value of the sequence has reached Long.MAX_VALUE, the sequence resets to 1 before continuing.- Returns:
- the next number in the sequence
-