Package com.github.f4b6a3.uuid.creator
Class AbstractRandomBasedUuidCreator
- java.lang.Object
-
- com.github.f4b6a3.uuid.creator.AbstractUuidCreator
-
- com.github.f4b6a3.uuid.creator.AbstractRandomBasedUuidCreator
-
- All Implemented Interfaces:
NoArgumentsUuidCreator
- Direct Known Subclasses:
AltCombGuidCreator,CombGuidCreator,RandomBasedUuidCreator
public abstract class AbstractRandomBasedUuidCreator extends AbstractUuidCreator implements NoArgumentsUuidCreator
Factory that creates random-based UUIDs.
-
-
Field Summary
Fields Modifier and Type Field Description protected Randomrandom-
Fields inherited from class com.github.f4b6a3.uuid.creator.AbstractUuidCreator
version, versionBits
-
-
Constructor Summary
Constructors Constructor Description AbstractRandomBasedUuidCreator()AbstractRandomBasedUuidCreator(UuidVersion version)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description UUIDcreate()Returns a random-based UUID. ### RFC-4122 - 4.4.<T extends AbstractRandomBasedUuidCreator>
TwithFastRandomGenerator()Replaces the default random generator with a faster one.<T extends AbstractRandomBasedUuidCreator>
TwithRandomGenerator(Random random)Replaces the default random generator with another one.-
Methods inherited from class com.github.f4b6a3.uuid.creator.AbstractUuidCreator
applyVariantBits, applyVersionBits, getVersion
-
-
-
-
Field Detail
-
random
protected Random random
-
-
Constructor Detail
-
AbstractRandomBasedUuidCreator
public AbstractRandomBasedUuidCreator()
-
AbstractRandomBasedUuidCreator
public AbstractRandomBasedUuidCreator(UuidVersion version)
-
-
Method Detail
-
create
public UUID create()
Returns a random-based UUID. ### RFC-4122 - 4.4. Algorithms for Creating a UUID from Truly Random or Pseudo-Random Numbers (1) Set the two most significant bits (bits 6 and 7) of the clock_seq_hi_and_reserved to zero and one, respectively. (2) Set the four most significant bits (bits 12 through 15) of the time_hi_and_version field to the 4-bit version number from Section 4.1.3. (3) Set all the other bits to randomly (or pseudo-randomly) chosen values.- Specified by:
createin interfaceNoArgumentsUuidCreator- Returns:
- a random-based UUID
-
withRandomGenerator
public <T extends AbstractRandomBasedUuidCreator> T withRandomGenerator(Random random)
Replaces the default random generator with another one. The default random generator isSecureRandom. SeeRandom.- Type Parameters:
T- the type parameter- Parameters:
random- a random generator- Returns:
AbstractRandomBasedUuidCreator
-
withFastRandomGenerator
public <T extends AbstractRandomBasedUuidCreator> T withFastRandomGenerator()
Replaces the default random generator with a faster one. The substitute random generator isXorshift128PlusRandom. The host fingerprint is used to generate a salt for the random number generator. See:Xorshift128PlusRandomSee:FingerprintUtil.getFingerprint()- Type Parameters:
T- the type parameter- Returns:
AbstractRandomBasedUuidCreator
-
-