Class UuidValidator


  • public final class UuidValidator
    extends Object
    Utility for UUID validation.

    Using it is much faster than using on regular expression.

    Examples of valid string formats:

    • 12345678-abcd-abcd-abcd-123456789abcd (36 hexadecimal chars, lower case and with hyphen)
    • 12345678-ABCD-ABCD-ABCD-123456789ABCD (36 hexadecimal chars, UPPER CASE and with hyphen)
    • 12345678abcdabcdabcd123456789abcd (32 hexadecimal chars, lower case and WITHOUT hyphen)
    • 12345678ABCDABCDABCD123456789ABCD (32 hexadecimal chars, UPPER CASE and WITHOUT hyphen)
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      protected static boolean isParseable​(char[] chars)
      Checks if the UUID char array can be parsed.
      protected static boolean isParseable​(char[] chars, int version)
      Checks if the UUID char array can be parsed.
      static boolean isValid​(byte[] uuid)
      Checks if the UUID byte array is valid.
      static boolean isValid​(byte[] uuid, int version)
      Checks if the UUID byte array is valid.
      static boolean isValid​(char[] uuid)
      Checks if the UUID char array is valid.
      static boolean isValid​(char[] uuid, int version)
      Checks if the UUID char array is valid.
      static boolean isValid​(String uuid)
      Checks if the UUID string is valid.
      static boolean isValid​(String uuid, int version)
      Checks if the UUID string is valid.
      static boolean isValid​(UUID uuid)
      Checks if the UUID is valid.
      static boolean isValid​(UUID uuid, int version)
      Checks if the UUID is valid.
      protected static boolean isVersion​(byte[] bytes, int version)
      Checks the version number of a UUID byte array.
      protected static boolean isVersion​(char[] chars, int version)
      Checks the version number of a UUID char array.
      protected static boolean isVersion​(UUID uuid, int version)
      Checks the version number of a UUID.
      static void validate​(byte[] uuid)
      Checks if the UUID byte array is valid.
      static void validate​(byte[] uuid, int version)
      Checks if the UUID byte array is valid.
      static void validate​(char[] uuid)
      Checks if the UUID char array is valid.
      static void validate​(char[] uuid, int version)
      Checks if the UUID char array is valid.
      static void validate​(String uuid)
      Checks if the UUID string is a valid.
      static void validate​(String uuid, int version)
      Checks if the UUID string is a valid.
      static void validate​(UUID uuid)
      Checks if the UUID is valid.
      static void validate​(UUID uuid, int version)
      Checks if the UUID is valid.
    • Method Detail

      • isValid

        public static boolean isValid​(UUID uuid)
        Checks if the UUID is valid.
        Parameters:
        uuid - a UUID
        Returns:
        true if valid, false if invalid
      • isValid

        public static boolean isValid​(UUID uuid,
                                      int version)
        Checks if the UUID is valid.
        Parameters:
        uuid - a UUID
        version - a version number
        Returns:
        true if valid, false if invalid
      • isValid

        public static boolean isValid​(byte[] uuid)
        Checks if the UUID byte array is valid.
        Parameters:
        uuid - a UUID byte array
        Returns:
        true if valid, false if invalid
      • isValid

        public static boolean isValid​(byte[] uuid,
                                      int version)
        Checks if the UUID byte array is valid.
        Parameters:
        uuid - a UUID byte array
        version - a version number
        Returns:
        true if valid, false if invalid
      • isValid

        public static boolean isValid​(String uuid)
        Checks if the UUID string is valid.
        Parameters:
        uuid - a UUID string
        Returns:
        true if valid, false if invalid
      • isValid

        public static boolean isValid​(String uuid,
                                      int version)
        Checks if the UUID string is valid.
        Parameters:
        uuid - a UUID string
        version - a version number
        Returns:
        true if valid, false if invalid
      • isValid

        public static boolean isValid​(char[] uuid)
        Checks if the UUID char array is valid.
        Parameters:
        uuid - a UUID char array
        Returns:
        true if valid, false if invalid
      • isValid

        public static boolean isValid​(char[] uuid,
                                      int version)
        Checks if the UUID char array is valid.
        Parameters:
        uuid - a UUID char array
        version - a version number
        Returns:
        true if valid, false if invalid
      • validate

        public static void validate​(UUID uuid)
        Checks if the UUID is valid.
        Parameters:
        uuid - a UUID
        Throws:
        InvalidUuidException - if the argument is invalid
      • validate

        public static void validate​(UUID uuid,
                                    int version)
        Checks if the UUID is valid.
        Parameters:
        uuid - a UUID
        version - a version number
        Throws:
        InvalidUuidException - if the argument is invalid
      • validate

        public static void validate​(byte[] uuid)
        Checks if the UUID byte array is valid.
        Parameters:
        uuid - a UUID byte array
        Throws:
        InvalidUuidException - if the argument is invalid
      • validate

        public static void validate​(byte[] uuid,
                                    int version)
        Checks if the UUID byte array is valid.
        Parameters:
        uuid - a UUID byte array
        version - a version number
        Throws:
        InvalidUuidException - if the argument is invalid
      • validate

        public static void validate​(String uuid)
        Checks if the UUID string is a valid.
        Parameters:
        uuid - a UUID string
        Throws:
        InvalidUuidException - if the argument is invalid
      • validate

        public static void validate​(String uuid,
                                    int version)
        Checks if the UUID string is a valid.
        Parameters:
        uuid - a UUID string
        version - a version number
        Throws:
        InvalidUuidException - if the argument is invalid
      • validate

        public static void validate​(char[] uuid)
        Checks if the UUID char array is valid.
        Parameters:
        uuid - a UUID char array
        Throws:
        InvalidUuidException - if the argument is invalid
      • validate

        public static void validate​(char[] uuid,
                                    int version)
        Checks if the UUID char array is valid.
        Parameters:
        uuid - a UUID char array
        version - a version number
        Throws:
        InvalidUuidException - if the argument is invalid
      • isParseable

        protected static boolean isParseable​(char[] chars)
        Checks if the UUID char array can be parsed.
        Parameters:
        chars - a char array
        Returns:
        true if valid, false if invalid
      • isParseable

        protected static boolean isParseable​(char[] chars,
                                             int version)
        Checks if the UUID char array can be parsed.
        Parameters:
        chars - a char array
        version - a version number
        Returns:
        true if valid, false if invalid
      • isVersion

        protected static boolean isVersion​(UUID uuid,
                                           int version)
        Checks the version number of a UUID.
        Parameters:
        uuid - a UUID
        version - a version number
        Returns:
        true if the UUID version is equal to the expected version number
      • isVersion

        protected static boolean isVersion​(byte[] bytes,
                                           int version)
        Checks the version number of a UUID byte array.
        Parameters:
        bytes - a byte array
        version - a version number
        Returns:
        true if the UUID version is equal to the expected version number
      • isVersion

        protected static boolean isVersion​(char[] chars,
                                           int version)
        Checks the version number of a UUID char array.
        Parameters:
        chars - a string
        version - a version number
        Returns:
        true if the UUID version is equal to the expected version number