com.jgoodies.validation.util
Class ValidationUtils

java.lang.Object
  extended by com.jgoodies.validation.util.ValidationUtils

public final class ValidationUtils
extends Object

Consists exclusively of static methods for validating input values by testing and comparing single and multiple values.

The Jakarta Commons Lang library contains more classes and methods useful for validation. The Utils string and character tests in this ValidationUtils class are compatible with the Jakarta Commons Lang StringUtils methods.

Version:
$Revision: 1.19 $
Author:
Karsten Lentzsch
See Also:
Calendar

Method Summary
static Calendar getRelativeCalendar(Calendar from, int offsetDays)
          Computes the day that has the given offset in days from the specified from date and returns it as an instance of Calendar.
static Calendar getRelativeCalendar(int offsetDays)
          Computes the day that has the given offset in days to today and returns it as an instance of Calendar.
static Date getRelativeDate(int offsetDays)
          Computes the day that has the given offset in days to today and returns it as an instance of Date.
static boolean hasBoundedLength(String str, int min, int max)
          Checks and answers if the length of the given string is in the bounds as specified by the interval [min, max].
static boolean hasMaximumLength(String str, int max)
          Checks and answers if the given string is shorter than the specified maximum length.
static boolean hasMinimumLength(String str, int min)
          Checks and answers if the given string has at least the specified minimum length.
static boolean isAlpha(String str)
          Checks and answers if the given string contains only unicode letters.
static boolean isAlphanumeric(String str)
          Checks and answers if the given string contains only unicode letters or digits.
static boolean isAlphanumericSpace(String str)
          Checks and answers if the given string contains only unicode letters or digits or space (' ').
static boolean isAlphaSpace(String str)
          Checks and answers if the given string contains only unicode letters and space (' ').
static boolean isFutureDay(Date date)
          Determines and answers if the day of the given Date is in the future.
static boolean isNumeric(String str)
          Checks and answers if the given string contains only unicode digits.
static boolean isNumericSpace(String str)
          Checks and answers if the given string contains only unicode digits or space (' ').
static boolean isPastDay(Date date)
          Determines and answers if the day of the given Date is in the past.
static boolean isToday(Date date)
          Determines and answers if the given Date is today.
static boolean isTomorrow(Date date)
          Determines and answers if the given Date is tomorrow.
static boolean isYesterday(Date date)
          Determines and answers if the given Date is yesterday.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

hasMinimumLength

public static boolean hasMinimumLength(String str,
                                       int min)
Checks and answers if the given string has at least the specified minimum length. Strings that are null or contain only blanks have length 0.
 ValidationUtils.hasMinimumLength(null,  2) == false
 ValidationUtils.hasMinimumLength("",    2) == false
 ValidationUtils.hasMinimumLength(" ",   2) == false
 ValidationUtils.hasMinimumLength("   ", 2) == false
 ValidationUtils.hasMinimumLength("Hi ", 2) == true
 ValidationUtils.hasMinimumLength("Ewa", 2) == true
 

Parameters:
str - the string to check
min - the minimum length
Returns:
true if the length is greater or equal to the minimum, false otherwise

hasMaximumLength

public static boolean hasMaximumLength(String str,
                                       int max)
Checks and answers if the given string is shorter than the specified maximum length. Strings that are null or contain only blanks have length 0.
 ValidationUtils.hasMaximumLength(null,  2) == true
 ValidationUtils.hasMaximumLength("",    2) == true
 ValidationUtils.hasMaximumLength(" ",   2) == true
 ValidationUtils.hasMaximumLength("   ", 2) == true
 ValidationUtils.hasMaximumLength("Hi ", 2) == true
 ValidationUtils.hasMaximumLength("Ewa", 2) == false
 

Parameters:
str - the string to check
max - the maximum length
Returns:
true if the length is less than or equal to the minimum, false otherwise

hasBoundedLength

public static boolean hasBoundedLength(String str,
                                       int min,
                                       int max)
Checks and answers if the length of the given string is in the bounds as specified by the interval [min, max]. Strings that are null or contain only blanks have length 0.
 ValidationUtils.hasBoundedLength(null,  1, 2) == false
 ValidationUtils.hasBoundedLength("",    1, 2) == false
 ValidationUtils.hasBoundedLength(" ",   1, 2) == false
 ValidationUtils.hasBoundedLength("   ", 1, 2) == false
 ValidationUtils.hasBoundedLength("Hi ", 1, 2) == true
 ValidationUtils.hasBoundedLength("Ewa", 1, 2) == false
 

Parameters:
str - the string to check
min - the minimum length
max - the maximum length
Returns:
true if the length is in the interval, false otherwise
Throws:
IllegalArgumentException - if min > max

isAlpha

public static boolean isAlpha(String str)
Checks and answers if the given string contains only unicode letters. null returns false, an empty string ("") returns true.
 ValidationUtils.isAlpha(null)   == false
 ValidationUtils.isAlpha("")     == true
 ValidationUtils.isAlpha("   ")  == false
 ValidationUtils.isAlpha("abc")  == true
 ValidationUtils.isAlpha("ab c") == false
 ValidationUtils.isAlpha("ab2c") == false
 ValidationUtils.isAlpha("ab-c") == false
 

Parameters:
str - the string to check, may be null
Returns:
true if the string contains only unicode letters, and is non-null
Since:
1.2

isAlphaSpace

public static boolean isAlphaSpace(String str)
Checks and answers if the given string contains only unicode letters and space (' '). null returns false, an empty string ("") returns true.
 ValidationUtils.isAlphaSpace(null)   == false
 ValidationUtils.isAlphaSpace("")     == true
 ValidationUtils.isAlphaSpace("   ")  == true
 ValidationUtils.isAlphaSpace("abc")  == true
 ValidationUtils.isAlphaSpace("ab c") == true
 ValidationUtils.isAlphaSpace("ab2c") == false
 ValidationUtils.isAlphaSpace("ab-c") == false
 

Parameters:
str - the string to check, may be null
Returns:
true if the string contains only unicode letters and space, and is non-null
Since:
1.2

isAlphanumeric

public static boolean isAlphanumeric(String str)
Checks and answers if the given string contains only unicode letters or digits. null returns false, an empty string ("") returns true.
 ValidationUtils.isAlphanumeric(null)   == false
 ValidationUtils.isAlphanumeric("")     == true
 ValidationUtils.isAlphanumeric("   ")  == false
 ValidationUtils.isAlphanumeric("abc")  == true
 ValidationUtils.isAlphanumeric("ab c") == false
 ValidationUtils.isAlphanumeric("ab2c") == true
 ValidationUtils.isAlphanumeric("ab-c") == false
 ValidationUtils.isAlphanumeric("123")  == true
 ValidationUtils.isAlphanumeric("12 3") == false
 ValidationUtils.isAlphanumeric("12-3") == false
 

Parameters:
str - the string to check, may be null
Returns:
true if the string contains only unicode letters or digits, and is non-null
Since:
1.2

isAlphanumericSpace

public static boolean isAlphanumericSpace(String str)
Checks and answers if the given string contains only unicode letters or digits or space (' '). null returns false, an empty string ("") returns true.
 ValidationUtils.isAlphanumericSpace(null)   == false
 ValidationUtils.isAlphanumericSpace("")     == true
 ValidationUtils.isAlphanumericSpace("   ")  == true
 ValidationUtils.isAlphanumericSpace("abc")  == true
 ValidationUtils.isAlphanumericSpace("ab c") == true
 ValidationUtils.isAlphanumericSpace("ab2c") == true
 ValidationUtils.isAlphanumericSpace("ab-c") == false
 ValidationUtils.isAlphanumericSpace("123")  == true
 ValidationUtils.isAlphanumericSpace("12 3") == true
 ValidationUtils.isAlphanumericSpace("12-3") == false
 

Parameters:
str - the string to check, may be null
Returns:
true if the string contains only unicode letters, digits or space (' '), and is non-null
Since:
1.2

isNumeric

public static boolean isNumeric(String str)
Checks and answers if the given string contains only unicode digits. A decimal point is not a unicode digit and returns false. null returns false, an empty string ("") returns true.
 ValidationUtils.isNumeric(null)   == false
 ValidationUtils.isNumeric("")     == true
 ValidationUtils.isNumeric("   ")  == false
 ValidationUtils.isNumeric("abc")  == false
 ValidationUtils.isNumeric("ab c") == false
 ValidationUtils.isNumeric("ab2c") == false
 ValidationUtils.isNumeric("ab-c") == false
 ValidationUtils.isNumeric("123")  == true
 ValidationUtils.isNumeric("12 3") == false
 ValidationUtils.isNumeric("12-3") == false
 ValidationUtils.isNumeric("12.3") == false
 

Parameters:
str - the string to check, may be null
Returns:
true if the string contains only unicode digits, and is non-null
Since:
1.2

isNumericSpace

public static boolean isNumericSpace(String str)
Checks and answers if the given string contains only unicode digits or space (' '). A decimal point is not a unicode digit and returns false. null returns false, an empty string ("") returns true.
 ValidationUtils.isNumericSpace(null)   == false
 ValidationUtils.isNumericSpace("")     == true
 ValidationUtils.isNumericSpace("   ")  == true
 ValidationUtils.isNumericSpace("abc")  == false
 ValidationUtils.isNumericSpace("ab c") == false
 ValidationUtils.isNumericSpace("ab2c") == false
 ValidationUtils.isNumericSpace("ab-c") == false
 ValidationUtils.isNumericSpace("123")  == true
 ValidationUtils.isNumericSpace("12 3") == true
 ValidationUtils.isNumericSpace("12-3") == false
 ValidationUtils.isNumericSpace("12.3") == false
 

Parameters:
str - the string to check, may be null
Returns:
true if the string contains only unicode digits or space, and is non-null
Since:
1.2

isPastDay

public static boolean isPastDay(Date date)
Determines and answers if the day of the given Date is in the past.

Parameters:
date - the date to check
Returns:
true if in the past, false otherwise

isYesterday

public static boolean isYesterday(Date date)
Determines and answers if the given Date is yesterday.

Parameters:
date - the date to check
Returns:
true if yesterday, false otherwise

isToday

public static boolean isToday(Date date)
Determines and answers if the given Date is today.

Parameters:
date - the date to check
Returns:
true if today, false otherwise

isTomorrow

public static boolean isTomorrow(Date date)
Determines and answers if the given Date is tomorrow.

Parameters:
date - the date to check
Returns:
true if tomorrow, false otherwise

isFutureDay

public static boolean isFutureDay(Date date)
Determines and answers if the day of the given Date is in the future.

Parameters:
date - the date to check
Returns:
true if in the future, false otherwise

getRelativeDate

public static Date getRelativeDate(int offsetDays)
Computes the day that has the given offset in days to today and returns it as an instance of Date.

Parameters:
offsetDays - the offset in day relative to today
Returns:
the Date that is the begin of the day with the specified offset

getRelativeCalendar

public static Calendar getRelativeCalendar(int offsetDays)
Computes the day that has the given offset in days to today and returns it as an instance of Calendar.

Parameters:
offsetDays - the offset in day relative to today
Returns:
a Calendar instance that is the begin of the day with the specified offset

getRelativeCalendar

public static Calendar getRelativeCalendar(Calendar from,
                                           int offsetDays)
Computes the day that has the given offset in days from the specified from date and returns it as an instance of Calendar.

Parameters:
from - the base date as Calendar instance
offsetDays - the offset in day relative to today
Returns:
a Calendar instance that is the begin of the day with the specified offset from the given day


Copyright © 2003-2011 JGoodies Karsten Lentzsch. All Rights Reserved.