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:
PrefixCombCreator,RandomBasedUuidCreator,ShortPrefixCombCreator,ShortSuffixCombCreator,SuffixCombCreator
public abstract class AbstractRandomBasedUuidCreator extends AbstractUuidCreator implements NoArgumentsUuidCreator
Factory that creates random-based UUIDs.
-
-
Field Summary
Fields Modifier and Type Field Description protected RandomStrategyrandomStrategy-
Fields inherited from class com.github.f4b6a3.uuid.creator.AbstractUuidCreator
version, versionBits
-
-
Constructor Summary
Constructors Constructor Description 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>
TwithRandomGenerator(Random random)Replaces the default random strategy with another that uses the inputRandominstance.<T extends AbstractRandomBasedUuidCreator>
TwithRandomStrategy(RandomStrategy randomStrategy)Replaces the default random strategy with another.-
Methods inherited from class com.github.f4b6a3.uuid.creator.AbstractUuidCreator
getUuid, getUuid, getVersion
-
-
-
-
Field Detail
-
randomStrategy
protected RandomStrategy randomStrategy
-
-
Constructor Detail
-
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
-
withRandomStrategy
public <T extends AbstractRandomBasedUuidCreator> T withRandomStrategy(RandomStrategy randomStrategy)
Replaces the default random strategy with another. The default random strategy usesSecureRandom. SeeRandom.- Type Parameters:
T- the type parameter- Parameters:
randomStrategy- a random strategy- Returns:
AbstractRandomBasedUuidCreator
-
withRandomGenerator
public <T extends AbstractRandomBasedUuidCreator> T withRandomGenerator(Random random)
Replaces the default random strategy with another that uses the inputRandominstance. It replaces the internalDefaultRandomStrategywithOtherRandomStrategy.- Type Parameters:
T- the type parameter- Parameters:
random- a random generator- Returns:
AbstractRandomBasedUuidCreator
-
-