Class UniqueIdentifiers

java.lang.Object
dev.rafandoo.cup.utils.UniqueIdentifiers

public final class UniqueIdentifiers extends Object
The UniqueIdentifiers class provides a set of static methods for generating various types of unique identifiers, including UUIDs (Versions 1 to 7) and ULIDs.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static UUID
    convertUlidToUUID(com.github.f4b6a3.ulid.Ulid ulid)
    Converts a ULID to a UUID (RFC-4122 format).
    static UUID
    convertUlidToUUIDv4(com.github.f4b6a3.ulid.Ulid ulid)
    Converts a ULID to a Version 4 UUID.
    static com.github.f4b6a3.ulid.Ulid
    getHashUlid(long time, String name)
    Generates a hash-based ULID using the specified timestamp and name.
    static com.github.f4b6a3.ulid.Ulid
    Generates a monotonic ULID, which guarantees that ULIDs are ordered if generated within the same millisecond.
    static com.github.f4b6a3.ulid.Ulid
    Generates a fast ULID.
    static com.github.f4b6a3.ulid.Ulid
    Generates a ULID (Universally Unique Lexicographically Sortable Identifier).
    static com.github.f4b6a3.ulid.Ulid
    Converts a string into a ULID.
    static Instant
    getUlidInstant(com.github.f4b6a3.ulid.Ulid ulid)
    Extracts the timestamp from a ULID and returns it as an Instant.
    static UUID
    Converts a string into a UUID.
    static UUID
    Generates a time-based UUID (Version 1).
    static UUID
    getUUIDv2(int localIdentifier)
    Generates a DCE Security UUID (Version 2).
    static UUID
    Generates a name-based UUID (Version 3) using MD5 hashing.
    static UUID
    Generates a random-based UUID (Version 4).
    static UUID
    Generates a name-based UUID (Version 5) using SHA-1 hashing.
    static UUID
    Generates a time-ordered UUID (Version 6).
    static UUID
    Generates a Unix Epoch time-based UUID (Version 7).
    static boolean
    Checks if a ULID is valid.
    static boolean
    Checks if a UUID is valid.

    Methods inherited from class java.lang.Object

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

    • UniqueIdentifiers

      public UniqueIdentifiers()
  • Method Details

    • getUUIDv1

      public static UUID getUUIDv1()
      Generates a time-based UUID (Version 1). This UUID includes a timestamp and a machine identifier.
      Returns:
      a UUIDv1.
    • getUUIDv2

      public static UUID getUUIDv2(int localIdentifier)
      Generates a DCE Security UUID (Version 2). This UUID includes a timestamp, local domain, and local identifier.
      Parameters:
      localIdentifier - the local identifier to include in the UUID.
      Returns:
      a UUIDv2.
    • getUUIDv3

      public static UUID getUUIDv3(String name)
      Generates a name-based UUID (Version 3) using MD5 hashing. The generated UUID is based on the given name and the URL namespace.
      Parameters:
      name - the name to hash into a UUID.
      Returns:
      a UUIDv3.
    • getUUIDv4

      public static UUID getUUIDv4()
      Generates a random-based UUID (Version 4). This UUID is purely random and does not contain any timestamp or machine identifier.
      Returns:
      a UUIDv4.
    • getUUIDv5

      public static UUID getUUIDv5(String name)
      Generates a name-based UUID (Version 5) using SHA-1 hashing. The generated UUID is based on the given name and the URL namespace.
      Parameters:
      name - the name to hash into a UUID.
      Returns:
      a UUIDv5.
    • getUUIDv6

      public static UUID getUUIDv6()
      Generates a time-ordered UUID (Version 6). This UUID includes a timestamp, and its ordering is optimized for database indexing.
      Returns:
      a UUIDv6.
    • getUUIDv7

      public static UUID getUUIDv7()
      Generates a Unix Epoch time-based UUID (Version 7). This UUID includes a timestamp with millisecond precision and random data.
      Returns:
      a UUIDv7.
    • getULID

      public static com.github.f4b6a3.ulid.Ulid getULID()
      Generates a ULID (Universally Unique Lexicographically Sortable Identifier). This identifier is based on the current time and random data.
      Returns:
      a ULID.
    • getMonotonicUlid

      public static com.github.f4b6a3.ulid.Ulid getMonotonicUlid()
      Generates a monotonic ULID, which guarantees that ULIDs are ordered if generated within the same millisecond.
      Returns:
      a monotonic ULID.
    • getHashUlid

      public static com.github.f4b6a3.ulid.Ulid getHashUlid(long time, String name)
      Generates a hash-based ULID using the specified timestamp and name.
      Parameters:
      time - the timestamp to include in the ULID.
      name - the name to hash into the ULID.
      Returns:
      a hash-based ULID.
    • getQuickUlid

      public static com.github.f4b6a3.ulid.Ulid getQuickUlid()
      Generates a fast ULID. This method is optimized for speed.
      Returns:
      a fast ULID.
    • convertUlidToUUID

      public static UUID convertUlidToUUID(com.github.f4b6a3.ulid.Ulid ulid)
      Converts a ULID to a UUID (RFC-4122 format).
      Parameters:
      ulid - the ULID to convert.
      Returns:
      the equivalent UUID.
    • convertUlidToUUIDv4

      public static UUID convertUlidToUUIDv4(com.github.f4b6a3.ulid.Ulid ulid)
      Converts a ULID to a Version 4 UUID.
      Parameters:
      ulid - the ULID to convert.
      Returns:
      the equivalent UUIDv4.
    • getUlidInstant

      public static Instant getUlidInstant(com.github.f4b6a3.ulid.Ulid ulid)
      Extracts the timestamp from a ULID and returns it as an Instant.
      Parameters:
      ulid - the ULID to extract the timestamp from.
      Returns:
      the timestamp as an Instant.
    • isValidUlid

      public static boolean isValidUlid(String ulid)
      Checks if a ULID is valid.
      Parameters:
      ulid - the ULID to check.
      Returns:
      true if the ULID is valid, false otherwise.
    • isValidUUID

      public static boolean isValidUUID(String uuid)
      Checks if a UUID is valid.
      Parameters:
      uuid - the UUID to check.
      Returns:
      true if the UUID is valid, false otherwise.
    • getUUIDFromString

      public static UUID getUUIDFromString(String uuid)
      Converts a string into a UUID.
      Parameters:
      uuid - the string to convert.
      Returns:
      the UUID.
    • getUlidFromString

      public static com.github.f4b6a3.ulid.Ulid getUlidFromString(String ulid)
      Converts a string into a ULID.
      Parameters:
      ulid - the string to convert.
      Returns:
      the ULID.