public class GuidCreator extends Object
| 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 |
|---|
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> |
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 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()
UUID a UUID valueUlidCreatorException - an overrun exception if too many requests are made within the
same millisecond.public String createUlid()
public byte[] createBytes()
protected long getTimestamp()
protected void reset()
protected void increment()
UlidCreatorException - if an overrun 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()GuidCreatorCopyright © 2020. All rights reserved.