Class RandomIdGenerator
- java.lang.Object
-
- dk.cloudcreate.essentials.components.foundation.types.RandomIdGenerator
-
public final class RandomIdGenerator extends Object
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.Generatorsyou need to include thecom.fasterxml.uuid:java-uuid-generatordependency in your project.
Maven example:<dependency> <groupId>com.fasterxml.uuid</groupId> <artifactId>java-uuid-generator</artifactId> <version>?.?.?</version> </dependency> - Generates UUIDv1 time-based (i.e. sequential/monotonical) random id's
if
-
-
Constructor Summary
Constructors Constructor Description RandomIdGenerator()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Stringgenerate()Generates a new random id according to these rules: Generates UUIDv1 time-based (i.e.static booleanisOrderedIdGenerator()static voidoverrideRandomIdGenerator(Supplier<String> randomIdGenerator, boolean isSequentialIdGenerator)Override the default configured random id generator.
Example:
-
-
-
Method Detail
-
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
public static String 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()
-
-