public class UlidBasedGuidCreator extends Object implements NoArgumentsUuidCreator
| Modifier and Type | Field and Description |
|---|---|
protected long |
firstHigh |
protected long |
firstLow |
protected long |
high |
protected long |
low |
protected static long |
MASK_UNSIGNED_SHORT |
protected static String |
OVERRUN_MESSAGE |
protected long |
previousTimestamp |
protected Random |
random |
protected TimestampStrategy |
timestampStrategy |
| Constructor and Description |
|---|
UlidBasedGuidCreator() |
| Modifier and Type | Method and Description |
|---|---|
UUID |
create()
Return a GUID based on the ULID specification.
|
protected long |
getTimestamp()
Return the current timestamp and resets or increments the random part.
|
protected void |
increment()
Increment the random part of the GUID.
|
protected void |
reset()
Reset the random part of the GUID.
|
<T extends UlidBasedGuidCreator> |
withFastRandomGenerator()
Replaces the default random generator with a faster one.
|
<T extends UlidBasedGuidCreator> |
withRandomGenerator(Random random)
Replace the default random generator, in a fluent way, to another that
extends
Random. |
<T extends UlidBasedGuidCreator> |
withTimestampStrategy(TimestampStrategy timestampStrategy)
Used for changing the timestamp strategy.
|
protected long low
protected long high
protected long firstLow
protected long firstHigh
protected long previousTimestamp
protected Random random
protected static final long MASK_UNSIGNED_SHORT
protected static final String OVERRUN_MESSAGE
protected TimestampStrategy timestampStrategy
public UUID create()
create in interface NoArgumentsUuidCreatorUUID a UUID valueUuidCreatorException - an overrun exception if too many requests are made within the
same millisecond.protected long getTimestamp()
protected void reset()
protected void increment()
UuidCreatorException - if an overrun happens.public <T extends UlidBasedGuidCreator> T withTimestampStrategy(TimestampStrategy timestampStrategy)
timestampStrategy - a timestamp strategyUlidBasedGuidCreatorpublic <T extends UlidBasedGuidCreator> T withRandomGenerator(Random random)
Random.
The default random generator is SecureRandom.
For other faster pseudo-random generators, see XorshiftRandom and
its variations.
See Random.random - a random generatorUlidBasedGuidCreatorpublic <T extends UlidBasedGuidCreator> T withFastRandomGenerator()
Xorshift128PlusRandom and
FingerprintUtil.getFingerprint()UlidBasedGuidCreatorCopyright © 2020. All rights reserved.