org.javalid.core.validator
Class ValidatorSupport

java.lang.Object
  extended by org.javalid.core.validator.ValidatorSupport

public class ValidatorSupport
extends java.lang.Object

Contains a couple of shared methods used by the standard JavalidValidator implementation classes and some other core classes.

Changes for 1.1

Since:
1.0
Version:
1.1
Author:
M.Reuvers

Method Summary
static void compareCalendars(DateCheck annotation, java.util.Calendar calAnnotation, java.util.Calendar calValue, int mode, java.util.List<ValidationMessage> messages, java.lang.String validationPath)
          Compares two calendars according given mode (mode from @DateCheck).
static java.util.Calendar convertDateToCalendar(java.util.Date value, int convertType)
          Converts given date to a Calendar instance using given convertType (see DateCheck.TYPE_CONVERT_*)
static java.lang.String convertDateToString(java.util.Date date, java.lang.String pattern)
          Converts given date to a string, using given pattern.
static java.util.Date convertStringToDate(java.lang.String date, java.lang.String pattern)
          Converts given string to a date using given pattern, raises JavalidException if conversion fails
static java.math.BigDecimal getAsBigDecimal(java.lang.String value)
          Tries to convert value to BigDecimal, returns on success.
static java.math.BigInteger getAsBigInteger(java.lang.String value)
          Tries to convert value to BigInteger, returns on success.
static ValidatorCallInfo getValidatorCallInfo()
          Convenience method, which retrieves the current ValidatorInfo associated with this thread and clones it, then returns the value.
static double getValueAsDouble(java.lang.Object value)
          For given value, try to convert it to a double value and return it.
static boolean isBigMathNumber(java.lang.Object value)
          Returns true if given value is a big number (BigInteger or BigDecimal).
static boolean isEmptyString(java.lang.String value)
          Returns true if given string is either null or has a length of 0.
static boolean isNumericValue(java.lang.Object value)
          Returns true if given value is a numeric value (either as wrapper or as real primitive, which is now in a wrapper anyway).
static boolean validationMustBeAppliedToGroup(java.lang.String[] applyToGroups, java.lang.String groupName, java.lang.String[] jvGroupNames)
          Checks given applyToGroups array on given group name or JvGroup.GROUP_APPLY_ALL.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

validationMustBeAppliedToGroup

public static final boolean validationMustBeAppliedToGroup(java.lang.String[] applyToGroups,
                                                           java.lang.String groupName,
                                                           java.lang.String[] jvGroupNames)
Checks given applyToGroups array on given group name or JvGroup.GROUP_APPLY_ALL. If it matches returns true if groupName exists in the jvGroupNames array, false in all other cases.

Parameters:
applyToGroups - Contains the array of groups where to apply an annotation to
groupName - The name of the group to check for (note JvGroup.GROUP_APPLY_ALL found in the applyToGroups array will return true if groupName exists in jvGroupNames)
Returns:
True if match, false otherwise.

getValueAsDouble

public static final double getValueAsDouble(java.lang.Object value)
For given value, try to convert it to a double value and return it. Supports: If not supported raises a JvException.

Parameters:
value - The value to convert
Returns:
Value as double value

isNumericValue

public static final boolean isNumericValue(java.lang.Object value)
Returns true if given value is a numeric value (either as wrapper or as real primitive, which is now in a wrapper anyway). Valid wrappers are:

Parameters:
value - the value to check
Returns:
True if so, false otherwise.

isBigMathNumber

public static final boolean isBigMathNumber(java.lang.Object value)
Returns true if given value is a big number (BigInteger or BigDecimal).

Parameters:
value - The value to check
Returns:
True if BigInteger or BigDecimal

getAsBigInteger

public static final java.math.BigInteger getAsBigInteger(java.lang.String value)
Tries to convert value to BigInteger, returns on success. Raises JavalidException otherwise.

Parameters:
value - The value to convert
Returns:
BigInteger on success

getAsBigDecimal

public static final java.math.BigDecimal getAsBigDecimal(java.lang.String value)
Tries to convert value to BigDecimal, returns on success. Raises JavalidException otherwise.

Parameters:
value - The value to convert
Returns:
BigDecimal on success

isEmptyString

public static final boolean isEmptyString(java.lang.String value)
Returns true if given string is either null or has a length of 0.

Parameters:
value - The value to check
Returns:
True if string is null or length is 0.

getValidatorCallInfo

public static final ValidatorCallInfo getValidatorCallInfo()
Convenience method, which retrieves the current ValidatorInfo associated with this thread and clones it, then returns the value.

Returns:
Cloned ValidatorCallInfo instance

convertStringToDate

public static final java.util.Date convertStringToDate(java.lang.String date,
                                                       java.lang.String pattern)
Converts given string to a date using given pattern, raises JavalidException if conversion fails

Parameters:
date - The date to convert
pattern - The pattern to use
Returns:
Date
Since:
1.1

convertDateToString

public static final java.lang.String convertDateToString(java.util.Date date,
                                                         java.lang.String pattern)
Converts given date to a string, using given pattern.

Parameters:
date - Date to convert to string
pattern - The pattern to use
Returns:
Date converted as a string in given pattern

convertDateToCalendar

public static final java.util.Calendar convertDateToCalendar(java.util.Date value,
                                                             int convertType)
Converts given date to a Calendar instance using given convertType (see DateCheck.TYPE_CONVERT_*)

Parameters:
value - The value to convert to calendar
convertType - The convertType to use
Returns:
Calendar

compareCalendars

public static final void compareCalendars(DateCheck annotation,
                                          java.util.Calendar calAnnotation,
                                          java.util.Calendar calValue,
                                          int mode,
                                          java.util.List<ValidationMessage> messages,
                                          java.lang.String validationPath)
Compares two calendars according given mode (mode from @DateCheck). Any ValidationMessages are added to the list.

Parameters:
annotation - The annotation
calAnnotation - The annotation value that was ON the datecheck annotation
calValue - The actual value under validation (converted to a calendar)
mode - The mode to use
messages - The messages to add to
validationPath - The current validation path