Class Validation


  • public class Validation
    extends Object
    This class can validate values with respect to certain criteria.
    • Constructor Detail

      • Validation

        public Validation()
    • Method Detail

      • validateStringLength

        public static String validateStringLength​(String s,
                                                  int minLen,
                                                  int maxLen)
                                           throws ValidationException
        Validates the length of a string.
        Parameters:
        s - the string
        minLen - the minimum length (<= 0 if no minimum)
        maxLen - the maximum length (&tl;= 0 if no maximum)
        Returns:
        the string
        Throws:
        ValidationException - if the string length is invalid
      • validateStringRegex

        public static String validateStringRegex​(String s,
                                                 String regex)
                                          throws ValidationException
        Validates the string against a regular expression.
        Parameters:
        s - the string
        regex - the regular expression
        Returns:
        the string
        Throws:
        ValidationException - if the string does not match the regular expression
      • validateIntRange

        public static int validateIntRange​(int n,
                                           Integer min,
                                           Integer max)
                                    throws ValidationException
        Validates that an integer is in the specified range.
        Parameters:
        n - the integer
        min - the minimum value (null if no minimum)
        max - the maximum value (null if no maximum)
        Returns:
        the integer
        Throws:
        ValidationException - if the integer is not in the specified range
      • validateLongRange

        public static long validateLongRange​(long n,
                                             Long min,
                                             Long max)
                                      throws ValidationException
        Validates that a long is in the specified range.
        Parameters:
        n - the long
        min - the minimum value (null if no minimum)
        max - the maximum value (null if no maximum)
        Returns:
        the long
        Throws:
        ValidationException - if the long is not in the specified range
      • validateEmail

        public static String validateEmail​(String email)
                                    throws ValidationException
        Validates that a string is a valid email address.
        Parameters:
        email - the email address
        Returns:
        the email address
        Throws:
        ValidationException - if the email address is invalid
      • validateDate

        public static org.joda.time.LocalDate validateDate​(String dateStr)
                                                    throws ValidationException
        Validates that a string is a valid date formatted as yyyy-MM-dd.
        Parameters:
        dateStr - the date string
        Returns:
        the date
        Throws:
        ValidationException - if the date is invalid
      • validateTimeZone

        public static String validateTimeZone​(String timeZone)
                                       throws ValidationException
        Validates that a string is a valid time zone.
        Parameters:
        timeZone - the time zone
        Returns:
        the time zone
        Throws:
        ValidationException - if the time zone is invalid