Package org.apache.juneau.commons.utils
Class Uuid7
java.lang.Object
org.apache.juneau.commons.utils.Uuid7
Generator for
RFC 9562 §5.7 version-7 UUIDs.
A v7 UUID is time-ordered: a 48-bit big-endian Unix-milliseconds timestamp in the most-significant bits, followed by
the RFC 9562 version (7) and variant nibbles and SecureRandom-filled random bits. No JDK API produces v7
natively as of the Java 17 baseline this repo targets.
The SecureRandom used to fill the random bits is cached per thread (ThreadLocal) so minting is not a
fresh SecureRandom construction (and potential entropy syscall) on the request path.
See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic UUIDcreate()Generates a new version-7 UUID using the current wall-clock time.static UUIDGenerates a new version-7 UUID whose timestamp is read from the specified clock.static StringGenerates a new version-7 UUID and returns its canonical string form.static longExtracts the 48-bit Unix-milliseconds timestamp encoded in a v7 UUID's most-significant bits.
-
Method Details
-
create
Generates a new version-7 UUID using the current wall-clock time.- Returns:
- A new v7 UUID. Never
null .
-
create
Generates a new version-7 UUID whose timestamp is read from the specified clock.Lets tests pin the encoded timestamp with
Clock.fixed(Instant, ZoneId). The random bits are stillSecureRandom-filled, so two UUIDs minted against the same fixed clock differ.- Parameters:
clock- The clock supplying the Unix-milliseconds timestamp. Must not benull .- Returns:
- A new v7 UUID. Never
null .
-
createString
Generates a new version-7 UUID and returns its canonical string form.- Returns:
- The string form of a new v7 UUID. Never
null .
-
timestamp
Extracts the 48-bit Unix-milliseconds timestamp encoded in a v7 UUID's most-significant bits.- Parameters:
uuid- The UUID. Must not benull .- Returns:
- The encoded Unix-milliseconds timestamp.
-