Class UlidValidator


  • public final class UlidValidator
    extends Object
    • Method Detail

      • isValid

        public static boolean isValid​(String ulid)
        Checks if the string is a valid ULID. A valid ULID string is a sequence of 26 characters from Crockford's base 32 alphabet. It also checks if the timestamp is between 0 and 2^48-1.
         Examples of valid ULID strings:
         - 0123456789ABCDEFGHJKMNPKRS (26 alphanumeric, case insensitive, except U)
         - 0123456789ABCDEFGHIJKLMNOP (26 alphanumeric, case insensitive, including OIL, except U)
         - 0123456789-ABCDEFGHJK-MNPKRS (26 alphanumeric, case insensitive, except U, with hyphens)
         - 0123456789-ABCDEFGHIJ-KLMNOP (26 alphanumeric, case insensitive, including OIL, except U, with hyphens)
         
        Parameters:
        ulid - a ULID
        Returns:
        boolean true if valid
      • isValid

        public static boolean isValid​(char[] ulid)
        Checks if the char array is a valid ULID. A valid ULID string is a sequence of 26 characters from Crockford's base 32 alphabet. It also checks if the timestamp is between 0 and 2^48-1.
         Examples of valid ULID strings:
         - 0123456789ABCDEFGHJKMNPKRS (26 alphanumeric, case insensitive, except U)
         - 0123456789ABCDEFGHIJKLMNOP (26 alphanumeric, case insensitive, including OIL, except U)
         - 0123456789-ABCDEFGHJK-MNPKRS (26 alphanumeric, case insensitive, except U, with hyphens)
         - 0123456789-ABCDEFGHIJ-KLMNOP (26 alphanumeric, case insensitive, including OIL, except U, with hyphens)
         
        Parameters:
        ulid - a ULID char array
        Returns:
        boolean true if valid
      • validate

        public static void validate​(char[] ulid)
        Checks if the ULID char array is valid. See isValid(String).
        Parameters:
        ulid - a ULID char array
        Throws:
        InvalidUlidException - if invalid
      • isValidString

        protected static boolean isValidString​(char[] c)
        Checks if the string is a valid ULID. A valid ULID string is a sequence of 26 characters from Crockford's base 32 alphabet.
         Examples of valid ULID strings:
         - 0123456789ABCDEFGHJKMNPKRS (26 alphanumeric, case insensitive, except U)
         - 0123456789ABCDEFGHIJKLMNOP (26 alphanumeric, case insensitive, including OIL, except U)
         - 0123456789-ABCDEFGHJK-MNPKRS (26 alphanumeric, case insensitive, except U, with hyphens)
         - 0123456789-ABCDEFGHIJ-KLMNOP (26 alphanumeric, case insensitive, including OIL, except U, with hyphens)
         
        Parameters:
        c - a char array
        Returns:
        boolean true if valid