public class GuidCreator extends Object
| 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 |
| Constructor and Description |
|---|
GuidCreator() |
| Modifier and Type | Method and Description |
|---|---|
UUID |
create()
Return a GUID based on the ULID specification.
|
byte[] |
createBytes()
Return a ULID as byte sequence.
|
String |
createUlid()
Return a ULID.
|
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 GuidCreator> |
withFastRandomGenerator()
Replaces the default random generator with a faster one.
|
<T extends GuidCreator> |
withoutOverflowException()
Used to disable the overflow exception.
|
<T extends GuidCreator> |
withRandomGenerator(Random random)
Replace the default random generator, in a fluent way, to another that
extends
Random. |
<T extends GuidCreator> |
withTimestampStrategy(TimestampStrategy timestampStrategy)
Used for changing the timestamp strategy.
|
protected 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()
UUID a UUID valueUlidCreatorException - an overflow exception if too many requests within the same
millisecond causes an overflow when incrementing the random
bits of the GUID.public String createUlid()
public byte[] createBytes()
protected long getTimestamp()
protected void reset()
protected void increment()
UlidCreatorException - if an overflow happens.public <T extends GuidCreator> T withTimestampStrategy(TimestampStrategy timestampStrategy)
timestampStrategy - a timestamp strategyGuidCreatorpublic <T extends GuidCreator> 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 generatorGuidCreatorpublic <T extends GuidCreator> T withFastRandomGenerator()
Xorshift128PlusRandom and
FingerprintUtil.getFingerprint()GuidCreatorpublic <T extends GuidCreator> T withoutOverflowException()
GuidCreatorCopyright © 2020. All rights reserved.