Class UuidValidator


  • public class UuidValidator
    extends Object
    Utility class for validating and converting UUIDs.
    Author:
    Stefan Guilhen
    • Field Detail

      • UUID_REGEX_PATTERN

        protected static final Pattern UUID_REGEX_PATTERN
    • Method Detail

      • isValid

        public static boolean isValid​(String id)
        Validates that the specified id is a UUID.
        Parameters:
        id - the id to be validated.
        Returns:
        true if the id is a UUID; false otherwise.
      • validateAndConvert

        public static String validateAndConvert​(String id)
        Validates that the specified id is a UUID. If it is, the id itself is returned. Otherwise, it is discarded and a new UUID is created and returned.
        Parameters:
        id - the id to be validated.
        Returns:
        the id itself if it is a valid UUID, or a new generated UUID.