This class is primarily designed for manipulating Leach-Salz variant UUIDs, but it also supports the creation of UUIDs of other variants.
The layout of a variant 2 (Leach-Salz) UUID is as follows: The most significant long consists of the following unsigned fields:
0xFFFFFFFF00000000 time_low 0x00000000FFFF0000 time_mid 0x000000000000F000 version 0x0000000000000FFF time_hiThe least significant long consists of the following unsigned fields:
0xC000000000000000 variant 0x3FFF000000000000 clock_seq 0x0000FFFFFFFFFFFF node
The variant field contains a value which identifies the layout of the
UUID. The bit layout described above is valid only for a UUID with a variant value of 2, which indicates the Leach-Salz variant.
See
RFC 9562: Universally Unique Identifiers (UUIDs) for the complete specification,
including the UUID format, layouts, and algorithms for creating UUIDs.
There are eight defined types of UUIDs, each identified by a version number: time-based (version 1), DCE security (version 2), name-based with MD5 (version 3), randomly generated (version 4), name-based with SHA-1 (version 5), reordered time-based (version 6), Unix epoch time-based (version 7), and custom-defined layout (version 8).
| Modifier and Type | Class and Description |
|---|---|
| private static class |
| Modifier and Type | Field and Description |
|---|---|
| private static final JavaLangAccess | |
| private final long | |
| private final long | |
| private static final byte[] | |
| private static final long | serialVersionUID
Explicit serialVersionUID for interoperability. |
| Access | Constructor and Description |
|---|---|
| private | |
| public | UUID(long
The most significant bits of the mostSigBits, long UUIDThe least significant bits of the leastSigBits)UUIDConstructs a new |
| Modifier and Type | Method and Description |
|---|---|
| public int | Returns: The clock sequence of thisUUIDThe clock sequence value associated with this UUID. |
| public int | Returns: -1, 0 or 1 as thisUUID is less than, equal to, or
greater than valUUID to which this UUID is to be comparedImplements java. Compares this UUID with the specified UUID. |
| public boolean | Returns: true if the objects are the same; false
otherwiseThe object to be compared obj)Overrides java. Compares this object to the specified object. |
| public static UUID | Returns: AUUID with the specified valueA string that specifies a name)UUIDCreates a |
| private static UUID | |
| public long | Returns: The least significant 64 bits of this UUID's 128 bit valueReturns the least significant 64 bits of this UUID's 128 bit value. |
| public long | Returns: The most significant 64 bits of this UUID's 128 bit valueReturns the most significant 64 bits of this UUID's 128 bit value. |
| public int | Returns: A hash code value for thisUUIDOverrides java. Returns a hash code for this |
| private static long | Returns: A long containing 8 ASCII bytes representing the hex digitsEfficiently converts 8 hexadecimal digits to their ASCII representation using SIMD-style vector operations. |
| public static UUID | Returns: AUUID generated from the specified arrayA byte array to be used to construct a name)UUIDStatic factory to retrieve a type 3 (name based) |
| public long | |
| public static UUID | Returns: aUUID constructed using the given timestampthe number of milliseconds since midnight 1 Jan 1970 UTC,
leap seconds excluded. timestamp)Creates a type 7 UUID (UUIDv7) |
| private static long | |
| public static UUID | Returns: A randomly generatedUUIDStatic factory to retrieve a type 4 (pseudo randomly generated) UUID. |
| public long | |
| public String | Returns: A string representation of thisUUIDOverrides java. Returns a |
| public int | |
| public int |
| jla | back to summary |
|---|---|
| private static final JavaLangAccess jla | |
| leastSigBits | back to summary |
|---|---|
| private final long leastSigBits | |
| mostSigBits | back to summary |
|---|---|
| private final long mostSigBits | |
| NIBBLES | back to summary |
|---|---|
| private static final byte[] NIBBLES | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Explicit serialVersionUID for interoperability. | |
| UUID | back to summary |
|---|---|
| private UUID(byte[] data) | |
| UUID | back to summary |
|---|---|
| public UUID(long mostSigBits, long leastSigBits) Constructs a new
| |
| clockSequence | back to summary |
|---|---|
| public int clockSequence() The clock sequence value associated with this UUID. The 14 bit clock sequence value is constructed from the clock sequence field of this UUID. The clock sequence field is used to guarantee temporal uniqueness in a time-based UUID. The
| |
| compareTo | back to summary |
|---|---|
| public int compareTo(UUID val) Implements java. Compares this UUID with the specified UUID. The first of two UUIDs is greater than the second if the most significant field in which the UUIDs differ is greater for the first UUID. | |
| equals | back to summary |
|---|---|
| public boolean equals(Object obj) Overrides java. Compares this object to the specified object. The result is | |
| fromString | back to summary |
|---|---|
| public static UUID fromString(String name) Creates a
| |
| fromString1 | back to summary |
|---|---|
| private static UUID fromString1(String name) | |
| getLeastSignificantBits | back to summary |
|---|---|
| public long getLeastSignificantBits() Returns the least significant 64 bits of this UUID's 128 bit value.
| |
| getMostSignificantBits | back to summary |
|---|---|
| public long getMostSignificantBits() Returns the most significant 64 bits of this UUID's 128 bit value.
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Returns a hash code for this
| |
| hex8 | back to summary |
|---|---|
| private static long hex8(long i) Efficiently converts 8 hexadecimal digits to their ASCII representation using SIMD-style vector operations. This method processes multiple digits in parallel by treating a long value as eight 8-bit lanes, achieving significantly better performance compared to traditional loop-based conversion. The conversion algorithm works as follows: 1. Input expansion: Each 4-bit hex digit is expanded to 8 bits 2. Vector processing: - Add 6 to each digit: triggers carry flag for a-f digits - Mask with 0x10 pattern to isolate carry flags - Calculate ASCII adjustment: (carry << 1) + (carry >> 1) - (carry >> 4) - Add ASCII '0' base (0x30) and original value 3. Byte order adjustment for final output Performance characteristics:
ASCII conversion mapping:
Implementation Note The implementation leverages CPU vector processing capabilities through long integer operations. The algorithm is based on the observation that ASCII hex digits have a specific pattern that can be computed efficiently using carry flag manipulation.
| |
| nameUUIDFromBytes | back to summary |
|---|---|
| public static UUID nameUUIDFromBytes(byte[] name) Static factory to retrieve a type 3 (name based)
| |
| node | back to summary |
|---|---|
| public long node() The node value associated with this UUID. The 48 bit node value is constructed from the node field of this UUID. This field is intended to hold the IEEE 802 address of the machine that generated this UUID to guarantee spatial uniqueness. The node value is only meaningful in a time-based UUID, which has version type 1. If this UUID is not a time-based UUID then this method throws UnsupportedOperationException.
| |
| ofEpochMillis | back to summary |
|---|---|
| public static UUID ofEpochMillis(long timestamp) Creates a type 7 UUID (UUIDv7) API Note
Monotonicity (each subsequent value being greater than the last) is a primary characteristic
of
| |
| parse4Nibbles | back to summary |
|---|---|
| private static long parse4Nibbles(String name, int pos) | |
| randomUUID | back to summary |
|---|---|
| public static UUID randomUUID() Static factory to retrieve a type 4 (pseudo randomly generated) UUID.
The
| |
| timestamp | back to summary |
|---|---|
| public long timestamp() The timestamp value associated with this UUID. The 60 bit timestamp value is constructed from the time_low,
time_mid, and time_hi fields of this The timestamp value is only meaningful in a time-based UUID, which
has version type 1. If this
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Returns a The UUID string representation is as described by this BNF:
| |
| variant | back to summary |
|---|---|
| public int variant() The variant number associated with this
| |
| version | back to summary |
|---|---|
| public int version() The version number associated with this
| |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv static final SecureRandom |
| Access | Constructor and Description |
|---|---|
| private |
| numberGenerator | back to summary |
|---|---|
| pack-priv static final SecureRandom numberGenerator | |
| Holder | back to summary |
|---|---|
| private Holder() | |