Package eu.woolplatform.utils.validation
Class Validation
- java.lang.Object
-
- eu.woolplatform.utils.validation.Validation
-
public class Validation extends Object
This class can validate values with respect to certain criteria.
-
-
Constructor Summary
Constructors Constructor Description Validation()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static org.joda.time.LocalDatevalidateDate(String dateStr)Validates that a string is a valid date formatted as yyyy-MM-dd.static StringvalidateEmail(String email)Validates that a string is a valid email address.static intvalidateIntRange(int n, Integer min, Integer max)Validates that an integer is in the specified range.static longvalidateLongRange(long n, Long min, Long max)Validates that a long is in the specified range.static ObjectvalidateNotNull(Object obj)Validates that an object is not null.static StringvalidateStringLength(String s, int minLen, int maxLen)Validates the length of a string.static StringvalidateStringRegex(String s, String regex)Validates the string against a regular expression.static StringvalidateTimeZone(String timeZone)Validates that a string is a valid time zone.
-
-
-
Method Detail
-
validateStringLength
public static String validateStringLength(String s, int minLen, int maxLen) throws ValidationException
Validates the length of a string.- Parameters:
s- the stringminLen- 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 stringregex- 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 ValidationExceptionValidates that an integer is in the specified range.- Parameters:
n- the integermin- 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 ValidationExceptionValidates that a long is in the specified range.- Parameters:
n- the longmin- 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
-
validateNotNull
public static Object validateNotNull(Object obj) throws ValidationException
Validates that an object is not null.- Parameters:
obj- the object- Returns:
- the object
- Throws:
ValidationException- if the object is null
-
-