org.kuali.rice.krad.datadictionary.validation
Class ValidationUtils

java.lang.Object
  extended by org.kuali.rice.krad.datadictionary.validation.ValidationUtils

public class ValidationUtils
extends Object

ValidationUtils provides static utility methods for validation processing

Inherited from Kuali Student and adapted extensively

Author:
Kuali Rice Team (rice.collab@kuali.org)

Nested Class Summary
static class ValidationUtils.Result
          defines possible result values of a comparison operation
 
Constructor Summary
ValidationUtils()
           
 
Method Summary
static String buildPath(String attributePath, String attributeName)
          constructs a path by appending the attribute name to the provided path
static boolean compareValues(Object fieldValue, Object whenValue, DataType dataType, String operator, boolean isCaseSensitive, DateTimeService dateTimeService)
          compares the value provided by the user and the one specified by the WhenConstraint
static Object convertToDataType(Object value, DataType dataType, DateTimeService dateTimeService)
          attempts to convert the provided value to the given dataType
static Boolean getBoolean(Object o)
          converts the provided object into a boolean
static Date getDate(Object object, DateTimeService dateTimeService)
          determines whether the provided object is a date and tries to converts non-date values
static Double getDouble(Object o)
          converts the provided object into a double
static Float getFloat(Object o)
          converts the provided object into an float
static Integer getInteger(Object o)
          converts the provided object into an integer
static int getLastPathIndex(String attributePath)
          Used to get the rightmost index value of an attribute path.
static Long getLong(Object o)
          converts the provided object into a long
static String[] getPathTokens(String fieldPath)
          converts a path into an array of its path components
static String getString(Object o)
          converts the provided object into a string
static boolean hasText(String string)
          checks whether the string contains non-whitespace characters
static
<T> ValidationUtils.Result
isGreaterThan(T value, Comparable<T> limit)
          checks whether the provided value is greater than the limit given
static
<T> ValidationUtils.Result
isGreaterThanOrEqual(T value, Comparable<T> limit)
          checks whether the provided value is greater than or equal to the limit given
static
<T> ValidationUtils.Result
isLessThan(T value, Comparable<T> limit)
          checks whether the provided value is less than the limit given
static
<T> ValidationUtils.Result
isLessThanOrEqual(T value, Comparable<T> limit)
          checks whether the provided value is greater than the limit given
static boolean isNullOrEmpty(Object value)
          checks whether the provided object is null or empty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ValidationUtils

public ValidationUtils()
Method Detail

buildPath

public static String buildPath(String attributePath,
                               String attributeName)
constructs a path by appending the attribute name to the provided path

Parameters:
attributePath - - a string representation of specifically which attribute (at some depth) is being accessed
attributeName - - the attribute name
Returns:
the path

getLastPathIndex

public static int getLastPathIndex(String attributePath)
Used to get the rightmost index value of an attribute path.

Parameters:
attributePath -
Returns:
the right index of value of attribute path, -1 if path has no index

compareValues

public static boolean compareValues(Object fieldValue,
                                    Object whenValue,
                                    DataType dataType,
                                    String operator,
                                    boolean isCaseSensitive,
                                    DateTimeService dateTimeService)
compares the value provided by the user and the one specified by the WhenConstraint

Parameters:
fieldValue - - the value found in the field specified by a CaseConstraint's propertyName
whenValue - - the value specified by a WhenConstraint
dataType - - the data type of the field which caseConstraint's propertyName refers to
operator - - the relationship to check between the fieldValue and the whenValue
isCaseSensitive - - whether string comparison will be carried out in a case sensitive fashion
dateTimeService - - used to convert strings to dates
Returns:

getInteger

public static Integer getInteger(Object o)
converts the provided object into an integer

Parameters:
o - - the object to convert
Returns:
the integer value

getLong

public static Long getLong(Object o)
converts the provided object into a long

Parameters:
o - - the object to convert
Returns:
the long value

getFloat

public static Float getFloat(Object o)
converts the provided object into an float

Parameters:
o - - the object to convert
Returns:
the float value

getDouble

public static Double getDouble(Object o)
converts the provided object into a double

Parameters:
o - - the object to convert
Returns:
the double value

getDate

public static Date getDate(Object object,
                           DateTimeService dateTimeService)
                    throws IllegalArgumentException
determines whether the provided object is a date and tries to converts non-date values

Parameters:
object - - the object to convert/cast into a date
dateTimeService - - used to convert strings to dates
Returns:
a date object
Throws:
IllegalArgumentException

getString

public static String getString(Object o)
converts the provided object into a string

Parameters:
o - - the object to convert
Returns:
the string value

getBoolean

public static Boolean getBoolean(Object o)
converts the provided object into a boolean

Parameters:
o - - the object to convert
Returns:
the boolean value

hasText

public static boolean hasText(String string)
checks whether the string contains non-whitespace characters

Parameters:
string -
Returns:
true if the string contains at least one none-whitespace character, false otherwise

isNullOrEmpty

public static boolean isNullOrEmpty(Object value)
checks whether the provided object is null or empty

Parameters:
value - - the object to check
Returns:
true if the object is null or empty, false otherwise

convertToDataType

public static Object convertToDataType(Object value,
                                       DataType dataType,
                                       DateTimeService dateTimeService)
                                throws AttributeValidationException
attempts to convert the provided value to the given dataType

Parameters:
value - - the object to convert
dataType - - the data type to convert into
dateTimeService - - used to convert strings to dates
Returns:
the converted value if null or successful, otherwise throws an exception
Throws:
AttributeValidationException

isGreaterThan

public static <T> ValidationUtils.Result isGreaterThan(T value,
                                                       Comparable<T> limit)
checks whether the provided value is greater than the limit given

Type Parameters:
T -
Parameters:
value - - the object to check
limit - - the limit to use
Returns:
one of the values in ValidationUtils.Result

isGreaterThanOrEqual

public static <T> ValidationUtils.Result isGreaterThanOrEqual(T value,
                                                              Comparable<T> limit)
checks whether the provided value is greater than or equal to the limit given

Type Parameters:
T -
Parameters:
value - - the object to check
limit - - the limit to use
Returns:
one of the values in ValidationUtils.Result

isLessThan

public static <T> ValidationUtils.Result isLessThan(T value,
                                                    Comparable<T> limit)
checks whether the provided value is less than the limit given

Type Parameters:
T -
Parameters:
value - - the object to check
limit - - the limit to use
Returns:
one of the values in ValidationUtils.Result

isLessThanOrEqual

public static <T> ValidationUtils.Result isLessThanOrEqual(T value,
                                                           Comparable<T> limit)
checks whether the provided value is greater than the limit given

Type Parameters:
T -
Parameters:
value - - the object to check
limit - - the limit to use
Returns:
one of the values in ValidationUtils.Result

getPathTokens

public static String[] getPathTokens(String fieldPath)
converts a path into an array of its path components

Parameters:
fieldPath - - a string representation of specifically which attribute (at some depth) is being accessed
Returns:
the array of path components


Copyright © 2005-2013 The Kuali Foundation. All Rights Reserved.