public class LexicalOrderGuidCreator extends AbstractUuidCreator implements NoArgumentsUuidCreator
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
enableOverflowException |
protected long |
high |
protected long |
low |
protected static long |
MAX_HIGH |
protected static long |
MAX_LOW |
protected static String |
OVERFLOW_MESSAGE |
protected long |
previousTimestamp |
protected Random |
random |
protected TimestampStrategy |
timestampStrategy |
version, versionBits| Constructor and Description |
|---|
LexicalOrderGuidCreator() |
| 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 LexicalOrderGuidCreator> |
withFastRandomGenerator()
Replaces the default random generator with a faster one.
|
<T extends LexicalOrderGuidCreator> |
withoutOverflowException()
Used to disable the overflow exception.
|
<T extends LexicalOrderGuidCreator> |
withRandomGenerator(Random random)
Replace the default random generator, in a fluent way, to another that
extends
Random. |
<T extends LexicalOrderGuidCreator> |
withTimestampStrategy(TimestampStrategy timestampStrategy)
Used for changing the timestamp strategy.
|
getVariantBits, getVersion, getVersionBits, setVariantBits, setVersionBitsprotected static final long MAX_LOW
protected static final long MAX_HIGH
protected long previousTimestamp
protected boolean enableOverflowException
protected Random random
protected long low
protected long high
protected static final String OVERFLOW_MESSAGE
protected TimestampStrategy timestampStrategy
public UUID create()
create in interface NoArgumentsUuidCreatorUUID a UUID valueUuidCreatorException - an overflow exception if too many requests within the same
millisecond causes an overflow when incrementing the random
bits of the GUID.protected long getTimestamp()
protected void reset()
protected void increment()
UuidCreatorException - if an overflow happens.public <T extends LexicalOrderGuidCreator> T withTimestampStrategy(TimestampStrategy timestampStrategy)
timestampStrategy - a timestamp strategyLexicalOrderGuidCreatorpublic <T extends LexicalOrderGuidCreator> 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 generatorLexicalOrderGuidCreatorpublic <T extends LexicalOrderGuidCreator> T withFastRandomGenerator()
Xorshift128PlusRandom and
FingerprintUtil.getFingerprint()LexicalOrderGuidCreatorpublic <T extends LexicalOrderGuidCreator> T withoutOverflowException()
LexicalOrderGuidCreatorCopyright © 2020. All rights reserved.