Class UuidUtils

java.lang.Object
com.axelor.common.UuidUtils

public class UuidUtils extends Object
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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static Instant
    Extracts the Instant timestamp from a version 7 (time-based) UUID.
    static boolean
    isV4(UUID uuid)
    Checks if the provided UUID is of version 4 (random).
    static boolean
    isV7(UUID uuid)
    Checks if the provided UUID is of version 7 (time-based).
    static boolean
    isValid(String input)
    Validates if the given input string conforms to the standard 36-character UUID format
    static UUID
    parse(String input)
    Parses a string representation of a UUID and returns a UUID object.
    static UUID
    v4()
    Generates a version 4 (random) UUID.
    static UUID
    v7()
    Generates a version 7 (time-based) UUID.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • UuidUtils

      public UuidUtils()
  • Method Details

    • v4

      public static UUID v4()
      Generates a version 4 (random) UUID.
      Returns:
      a version 4 UUID
    • v7

      public static UUID v7()
      Generates a version 7 (time-based) UUID.
      Returns:
      a version 7 UUID
    • isV4

      public static boolean isV4(UUID uuid)
      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

      public static boolean isV7(UUID uuid)
      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

      public static Instant getInstant(UUID uuid)
      Extracts the Instant timestamp from a version 7 (time-based) UUID.
      Parameters:
      uuid - the UUID from which the timestamp will be extracted
      Returns:
      the Instant representing the timestamp embedded in the version 7 UUID
      Throws:
      IllegalArgumentException - if the given UUID is not a version 7 UUID
    • parse

      public static UUID parse(String input)
      Parses a string representation of a UUID and returns a UUID object.

      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, an IllegalArgumentException is thrown.

      Parameters:
      input - the string representation of the UUID to be parsed
      Returns:
      the UUID object represented by the input string
      Throws:
      IllegalArgumentException - if the input does not conform to the standard 36-character UUID format
    • isValid

      public static boolean isValid(String input)
      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