Module com.github.f4b6a3.uuid
Class TimeOrderedEpochFactory
- java.lang.Object
-
- com.github.f4b6a3.uuid.factory.UuidFactory
-
- com.github.f4b6a3.uuid.factory.AbstRandomBasedFactory
-
- com.github.f4b6a3.uuid.factory.AbstCombFactory
-
- com.github.f4b6a3.uuid.factory.standard.TimeOrderedEpochFactory
-
public final class TimeOrderedEpochFactory extends AbstCombFactory
Concrete factory for creating Unix epoch time-ordered unique identifiers (UUIDv7).UUIDv7 is a new UUID version proposed by Peabody and Davis. It is similar to Prefix COMB GUID and ULID.
This factory creates 3 types:
- Type 1 (default): this type is divided in 3 components, namely time, counter and random. The counter component is incremented by 1 when the time repeats. The random component is always randomized.
- Type 2 (plus 1): this type is divided in 2 components, namely time and monotonic random. The monotonic random component is incremented by 1 when the time repeats. This type of UUID is like a Monotonic ULID. It can be much faster than the other types.
- Type 3 (plus n): this type is also divided in 2 components, namely time and monotonic random. The monotonic random component is incremented by a random positive integer between 1 and 2^32. This type of UUID is also like a Monotonic ULID, but with a random increment instead of 1.
If the underlying runtime provides enough clock precision, the microseconds are also injected in the UUID, specifically in the
rand_afield, which is the name RFC 9562 gives to the 12 bits right after the milliseconds field, from left to right. Otherwise, these 12 bits are randomly generated.In JDK 11, we get 1 microsecond precision. However, in JDK 8, the maximum precision we can get is 1 millisecond. On Windows, it is even worse because the default precision is 15.625ms, due to the system clock's refresh rate of 64Hz.
- Since:
- 5.0.0
- See Also:
PrefixCombFactory, ULID Specification, New UUID formats, Revise Universally Unique Identifier Definitions (uuidrev)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTimeOrderedEpochFactory.BuilderConcrete builder for creating a Unix epoch time-ordered factory.-
Nested classes/interfaces inherited from class com.github.f4b6a3.uuid.factory.AbstRandomBasedFactory
AbstRandomBasedFactory.FastRandom, AbstRandomBasedFactory.IRandom, AbstRandomBasedFactory.SafeRandom
-
Nested classes/interfaces inherited from class com.github.f4b6a3.uuid.factory.UuidFactory
UuidFactory.Parameters
-
-
Field Summary
-
Fields inherited from class com.github.f4b6a3.uuid.factory.AbstCombFactory
instantFunction
-
Fields inherited from class com.github.f4b6a3.uuid.factory.AbstRandomBasedFactory
lock, random, UUID_BYTES
-
Fields inherited from class com.github.f4b6a3.uuid.factory.UuidFactory
version, versionMask
-
-
Constructor Summary
Constructors Constructor Description TimeOrderedEpochFactory()Default constructor.TimeOrderedEpochFactory(Clock clock)Constructor with a clock.TimeOrderedEpochFactory(LongSupplier randomFunction)Constructor with a function which return random numbers.TimeOrderedEpochFactory(LongSupplier randomFunction, Clock clock)Constructor with a function which a function which return random numbers and a clock.TimeOrderedEpochFactory(Random random)Constructor with a random.TimeOrderedEpochFactory(Random random, Clock clock)Constructor with a random and a clock.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static TimeOrderedEpochFactory.Builderbuilder()Returns a builder of Unix epoch time-ordered factory.UUIDcreate()Returns a time-ordered unique identifier (UUIDv7).UUIDcreate(UuidFactory.Parameters parameters)Returns a time-ordered unique identifier (UUIDv7) for a given instant.-
Methods inherited from class com.github.f4b6a3.uuid.factory.UuidFactory
getVersion, nameBytes, nameBytes, namespaceBytes, namespaceBytes, namespaceBytes, toUuid
-
-
-
-
Constructor Detail
-
TimeOrderedEpochFactory
public TimeOrderedEpochFactory()
Default constructor.
-
TimeOrderedEpochFactory
public TimeOrderedEpochFactory(Clock clock)
Constructor with a clock.- Parameters:
clock- a clock
-
TimeOrderedEpochFactory
public TimeOrderedEpochFactory(Random random)
Constructor with a random.- Parameters:
random- a random
-
TimeOrderedEpochFactory
public TimeOrderedEpochFactory(Random random, Clock clock)
Constructor with a random and a clock.- Parameters:
random- a randomclock- a clock
-
TimeOrderedEpochFactory
public TimeOrderedEpochFactory(LongSupplier randomFunction)
Constructor with a function which return random numbers.- Parameters:
randomFunction- a function
-
TimeOrderedEpochFactory
public TimeOrderedEpochFactory(LongSupplier randomFunction, Clock clock)
Constructor with a function which a function which return random numbers and a clock.- Parameters:
randomFunction- a functionclock- a clock
-
-
Method Detail
-
builder
public static TimeOrderedEpochFactory.Builder builder()
Returns a builder of Unix epoch time-ordered factory.- Returns:
- a builder
-
create
public UUID create()
Returns a time-ordered unique identifier (UUIDv7).- Specified by:
createin classUuidFactory- Returns:
- a UUIDv7
-
create
public UUID create(UuidFactory.Parameters parameters)
Returns a time-ordered unique identifier (UUIDv7) for a given instant.The random component is generated with each method invocation.
- Overrides:
createin classAbstRandomBasedFactory- Parameters:
instant- a given instant- Returns:
- a UUIDv7
-
-