Package com.helixframework.id.uuid
Class UuidUtil
java.lang.Object
com.helixframework.id.uuid.UuidUtil
Utility class for working with UUIDs providing methods for generation,
conversion, and validation of different UUID versions.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classA utility class for Version 4 UUID generation and manipulation.static final classstatic final classA utility class for Version 7 UUID generation and manipulation according to the IETF UUID draft specification. -
Method Summary
Modifier and TypeMethodDescriptionstatic intCompares two UUIDs lexicographically by comparing the most significant bits first, then the least significant bits.static UUIDfromBase64Url(String value) Creates UUID from URL-safe Base64 string.static UUIDfromBytes(byte[] bytes) Creates UUID from byte array.static booleanChecks if the UUID string represents a nil UUID.static booleanChecks if the UUID is nil (all bits set to zero).static booleanChecks if UUID conforms to RFC 4122 specification.static booleanChecks if UUID is version 1 (time-based).static booleanChecks if UUID is version 3 (name-based using MD5 hashing).static booleanChecks if UUID is version 4 (random or pseudo-random).static booleanChecks if UUID is version 5 (name-based using SHA-1 hashing).static booleanChecks if UUID is version 6 (reordered time-based).static booleanChecks if UUID is version 7 (Unix Epoch time-based).static UUIDnil()Creates a nil UUID (all bits set to zero).static Stringrandom()Generates a random UUID string.static UUIDrandom(long seed) Creates a random UUID using the same value for both most and least significant bits.static UUIDrandom(long seed1, long seed2) Creates a random UUID using separate values for most and least significant bits.static UUIDCreates a new UUID by copying the bit values from an existing UUID.static StringtoBase64Url(UUID uuid) Converts UUID to URL-safe Base64 string.static byte[]Converts UUID to a byte array.static StringConverts UUID to string representation.static UUIDAttempts to parse a UUID string.static UuidUtil.V4v4()Creates a new V4 UUID builder instance.static UuidUtil.V5v5()Creates a new V5 UUID builder instance.static UuidUtil.V7v7()Creates a new V7 UUID builder instance.static intGets the variant number of UUID.static intGets the version number of UUID.
-
Method Details
-
random
Generates a random UUID string.- Returns:
- random UUID as string
-
random
Creates a random UUID using the same value for both most and least significant bits.- Parameters:
seed- value to use for both most and least significant bits- Returns:
- randomly generated UUID
-
random
Creates a new UUID by copying the bit values from an existing UUID.- Parameters:
seed- UUID to copy bit values from- Returns:
- new UUID with the same bit values as seed
-
random
Creates a random UUID using separate values for most and least significant bits.- Parameters:
seed1- value to use for most significant bitsseed2- value to use for least significant bits- Returns:
- randomly generated UUID
-
nil
Creates a nil UUID (all bits set to zero).- Returns:
- nil UUID
-
isNil
Checks if the UUID is nil (all bits set to zero).- Parameters:
uuid- UUID to check- Returns:
- true if UUID is nil, false otherwise
-
isNil
Checks if the UUID string represents a nil UUID.- Parameters:
value- UUID string to check- Returns:
- true if the string represents a nil UUID, false otherwise
-
tryParse
Attempts to parse a UUID string.- Parameters:
value- string to parse- Returns:
- UUID if parsing successful, null otherwise
-
toBytes
Converts UUID to a byte array. The UUID is converted by putting its most significant bits followed by the least significant bits into a 16-byte array using ByteBuffer.- Parameters:
uuid- UUID to convert- Returns:
- 16-byte array representation of UUID
- Throws:
IllegalArgumentException- if uuid is null
-
fromBytes
Creates UUID from byte array.- Parameters:
bytes- byte array to convert- Returns:
- UUID created from bytes
- Throws:
IllegalArgumentException- if byte array is null or not 16 bytes long
-
toBase64Url
Converts UUID to URL-safe Base64 string.- Parameters:
uuid- UUID to convert- Returns:
- Base64 URL-encoded string, or null if input UUID is null
-
fromBase64Url
Creates UUID from URL-safe Base64 string.- Parameters:
value- Base64 URL-encoded string- Returns:
- UUID created from Base64 string, or null if the input string is null
- Throws:
IllegalArgumentException- if the decoded bytes are not a valid UUID (not 16 bytes)
-
compare
Compares two UUIDs lexicographically by comparing the most significant bits first, then the least significant bits.- Parameters:
uuid1- first UUID to compareuuid2- second UUID to compare- Returns:
- negative value if uuid1 less than uuid2, positive if uuid1 greater than uuid2, 0 if equal
- Throws:
IllegalArgumentException- if either UUID is null
-
toString
Converts UUID to string representation.- Parameters:
uuid- UUID to convert- Returns:
- string representation of UUID, or null if input UUID is null
-
version
Gets the version number of UUID.- Parameters:
uuid- UUID to check- Returns:
- version number of UUID (1-7), or -1 if uuid is null
-
variant
Gets the variant number of UUID.- Parameters:
uuid- UUID to check- Returns:
- variant number of UUID (0-3), or -1 if uuid is null
-
isRfc4122
Checks if UUID conforms to RFC 4122 specification.- Parameters:
uuid- UUID to check- Returns:
- true if UUID is RFC 4122 compliant, false otherwise
-
isV1
Checks if UUID is version 1 (time-based).- Parameters:
uuid- UUID to check- Returns:
- true if UUID is version 1, false otherwise
-
isV3
Checks if UUID is version 3 (name-based using MD5 hashing).- Parameters:
uuid- UUID to check- Returns:
- true if UUID is version 3, false otherwise
-
isV4
Checks if UUID is version 4 (random or pseudo-random).- Parameters:
uuid- UUID to check- Returns:
- true if UUID is version 4, false otherwise
-
isV5
Checks if UUID is version 5 (name-based using SHA-1 hashing).- Parameters:
uuid- UUID to check- Returns:
- true if UUID is version 5, false otherwise
-
isV6
Checks if UUID is version 6 (reordered time-based).- Parameters:
uuid- UUID to check- Returns:
- true if UUID is version 6, false otherwise
-
isV7
Checks if UUID is version 7 (Unix Epoch time-based).- Parameters:
uuid- UUID to check- Returns:
- true if UUID is version 7, false otherwise
-
v4
Creates a new V4 UUID builder instance.- Returns:
- V4 UUID builder instance
-
v5
Creates a new V5 UUID builder instance.- Returns:
- V5 UUID builder instance
-
v7
Creates a new V7 UUID builder instance.- Returns:
- V7 UUID builder instance
-