Class RandomIdGenerator
java.lang.Object
dk.cloudcreate.essentials.components.foundation.types.RandomIdGenerator
RandomId generator that either:
- Generates UUIDv1 time-based (i.e. sequential/monotonical) random id's
if
com.fasterxml.uuid.Generatorsis on the classpath - Otherwise it generates UUIDv4 random id's
using the default Java
UUID.randomUUID()generator. - The random-id generator provided to
overrideRandomIdGenerator(Supplier, boolean)
To add com.fasterxml.uuid.Generators you need to include the com.fasterxml.uuid:java-uuid-generator dependency in your project.
Maven example:
<dependency>
<groupId>com.fasterxml.uuid</groupId>
<artifactId>java-uuid-generator</artifactId>
<version>?.?.?</version>
</dependency>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Stringgenerate()Generates a new random id according to these rules: Generates UUIDv1 time-based (i.e.static booleanstatic voidoverrideRandomIdGenerator(Supplier<String> randomIdGenerator, boolean isSequentialIdGenerator) Override the default configured random id generator.
Example:
-
Constructor Details
-
RandomIdGenerator
public RandomIdGenerator()
-
-
Method Details
-
overrideRandomIdGenerator
public static void overrideRandomIdGenerator(Supplier<String> randomIdGenerator, boolean isSequentialIdGenerator) Override the default configured random id generator.
Example:overrideRandomIdGenerator(() -> Generators.timeBasedEpochGenerator().generate().toString());- Parameters:
randomIdGenerator- the new random id generator that generates a new random id every time it's called.
The provided random id generator MUST be thread safeisSequentialIdGenerator- Is this a sequential id generator
-
generate
Generates a new random id according to these rules:- Generates UUIDv1 time-based (i.e. sequential/monotonical) random id's
if
com.fasterxml.uuid.Generatorsis on the classpath - Otherwise it generates UUIDv4 random id's
using the default Java
UUID.randomUUID()generator. - The random-id generator provided to
overrideRandomIdGenerator(Supplier, boolean)
- Returns:
- a new random id
- Generates UUIDv1 time-based (i.e. sequential/monotonical) random id's
if
-
isOrderedIdGenerator
public static boolean isOrderedIdGenerator()
-