Class UlidUtil

java.lang.Object
com.helixframework.id.ulid.UlidUtil

public final class UlidUtil extends Object
Utility for working with ULIDs.
See Also:
  • Method Details

    • random

      public static String random()
      Generate a random ULID.
      Returns:
      ulid
    • random

      public static String random(long timestamp)
      Generate a random ULID with the specified timestamp component.
      Parameters:
      timestamp - timestamp
      Returns:
      ulid
    • random

      public static String random(Random rand)
      Generates a random ULID using the specified randomness source.
      Parameters:
      rand - randomness source
      Returns:
      ulid
    • random

      public static String random(Random rand, long timestamp)
      Generates a random ULID using the specified randomness source and timestamp component.
      Parameters:
      rand - randomness source
      timestamp - timestamp
      Returns:
      ulid
    • tryParse

      public static com.offbytwo.ulid.ULID.Value tryParse(String ulid)
      Tries to parse the supplied ULID.
      Parameters:
      ulid - ulid
      Returns:
      parsed value or null if the supplied value is not a valid ULID
    • next

      public static String next(String ulid)
      Generates the next monotonic ULID from the supplied ULID.

      This method will roll over the entropy portion in the event of an overflow.

      Parameters:
      ulid - starting ulid
      Returns:
      next monotonic ULID
    • strictlyNext

      public static Optional<String> strictlyNext(String ulid)
      Generates the next monotonic ULID from the supplied ULID. If an overflow occurs this method will return empty instead of rolling.
      Parameters:
      ulid - ulid
      Returns:
      next monotonic ULID
    • from

      public static String from(UUID uuid)
      Converts the supplied UUID to a ULID.
      Parameters:
      uuid - uuid
      Returns:
      ulid
    • from

      public static String from(byte[] bytes)
      Converts the supplied UUID bytes to a ULID.
      Parameters:
      bytes - uuid bytes
      Returns:
      ulid
    • toUUID

      public static UUID toUUID(String ulid)
      Converts the ULID to UUID.
      Parameters:
      ulid - ulid
      Returns:
      uuid
    • getTimestamp

      public static long getTimestamp(String ulid)
      Gets the timestamp component of the ULID.
      Parameters:
      ulid - ulid
      Returns:
      timestamp
    • getEntropy

      public static byte[] getEntropy(String ulid)
      Gets the entropy component of the ulid.
      Parameters:
      ulid - ulid
      Returns:
      entropy bytes
    • compareTo

      public static int compareTo(String ulid1, String ulid2)
      Compares two ULIDs lexicographically.
      Parameters:
      ulid1 - first ulid
      ulid2 - second ulid
      Returns:
      0 if the string is equal to the other string, < 0 if the string is lexicographically less than the other string, > 0 if the string is lexicographically greater than the other string (more characters)
    • isValid

      public static boolean isValid(String ulid)
      Checks to see if the supplied string is valid ULID.
      Parameters:
      ulid - ulid
      Returns:
      true if valid; otherwise false