Package com.axelor.common
Class UuidUtils
java.lang.Object
com.axelor.common.UuidUtils
Utility class for generating and handling UUIDs (Universally Unique Identifiers).
Supports generation of version 4 (random) and version 7 (time-based) UUIDs, as well as methods to check UUID versions and extract timestamps from version 7 UUIDs.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic InstantgetInstant(UUID uuid) Extracts theInstanttimestamp from a version 7 (time-based) UUID.static booleanChecks if the provided UUID is of version 4 (random).static booleanChecks if the provided UUID is of version 7 (time-based).static booleanValidates if the given input string conforms to the standard 36-character UUID formatstatic UUIDParses a string representation of a UUID and returns aUUIDobject.static UUIDv4()Generates a version 4 (random) UUID.static UUIDv7()Generates a version 7 (time-based) UUID.
-
Constructor Details
-
UuidUtils
public UuidUtils()
-
-
Method Details
-
v4
Generates a version 4 (random) UUID.- Returns:
- a version 4 UUID
-
v7
Generates a version 7 (time-based) UUID.- Returns:
- a version 7 UUID
-
isV4
Checks if the provided UUID is of version 4 (random).- Parameters:
uuid- the UUID to be checked- Returns:
- true if the UUID is of version 4, false otherwise
-
isV7
Checks if the provided UUID is of version 7 (time-based).- Parameters:
uuid- the UUID to be checked- Returns:
- true if the UUID is of version 7, false otherwise
-
getInstant
Extracts theInstanttimestamp from a version 7 (time-based) UUID.- Parameters:
uuid- the UUID from which the timestamp will be extracted- Returns:
- the
Instantrepresenting the timestamp embedded in the version 7 UUID - Throws:
IllegalArgumentException- if the given UUID is not a version 7 UUID
-
parse
Parses a string representation of a UUID and returns aUUIDobject.This method enforces a strict 36-character format (e.g., "f81d4fae-7dec-11d0-a765-00a0c91e6bf6"). It is recommended over
UUID.fromString(String)which can be unsafe as it accepts UUIDs in formats other than the standard 36-character representation. If the input does not meet this requirement, anIllegalArgumentExceptionis thrown.- Parameters:
input- the string representation of the UUID to be parsed- Returns:
- the
UUIDobject represented by the input string - Throws:
IllegalArgumentException- if the input does not conform to the standard 36-character UUID format
-
isValid
Validates if the given input string conforms to the standard 36-character UUID format- Parameters:
input- the string to be validated- Returns:
- true if the input string is a valid UUID format, false otherwise
-