Class ValidationUtils
java.lang.Object
org.kuali.rice.krad.datadictionary.validation.ValidationUtils
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
Nested ClassesModifier and TypeClassDescriptionstatic enumdefines possible result values of a comparison operation -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Stringconstructs a path by appending the attribute name to the provided pathstatic booleancompareValues(Object fieldValue, Object whenValue, DataType dataType, String operator, boolean isCaseSensitive, DateTimeService dateTimeService) compares the value provided by the user and the one specified by theWhenConstraintstatic ObjectconvertToDataType(Object value, DataType dataType, DateTimeService dateTimeService) attempts to convert the provided value to the given dataTypestatic BooleangetBoolean(Object o) converts the provided object into a booleanstatic DategetDate(Object object, DateTimeService dateTimeService) determines whether the provided object is a date and tries to converts non-date valuesstatic Doubleconverts the provided object into a doublestatic Floatconverts the provided object into an floatstatic IntegergetInteger(Object o) converts the provided object into an integerstatic intgetLastPathIndex(String attributePath) Used to get the rightmost index value of an attribute path.static Longconverts the provided object into a longstatic String[]getPathTokens(String fieldPath) converts a path into an array of its path componentsstatic Stringconverts the provided object into a stringstatic booleanchecks whether the string contains non-whitespace charactersstatic <T> ValidationUtils.ResultisGreaterThan(T value, Comparable<T> limit) checks whether the provided value is greater than the limit givenstatic <T> ValidationUtils.ResultisGreaterThanOrEqual(T value, Comparable<T> limit) checks whether the provided value is greater than or equal to the limit givenstatic <T> ValidationUtils.ResultisLessThan(T value, Comparable<T> limit) checks whether the provided value is less than the limit givenstatic <T> ValidationUtils.ResultisLessThanOrEqual(T value, Comparable<T> limit) checks whether the provided value is greater than the limit givenstatic booleanisNullOrEmpty(Object value) Checks whether the provided object is null, or if a String, List, Set or Map is empty.
-
Constructor Details
-
ValidationUtils
public ValidationUtils()
-
-
Method Details
-
buildPath
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 accessedattributeName- - the attribute name- Returns:
- the path
-
getLastPathIndex
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 theWhenConstraint- Parameters:
fieldValue- the value found in the field specified by aCaseConstraint'spropertyNamewhenValue- the value specified by aWhenConstraintdataType- the data type of the field which caseConstraint's propertyName refers tooperator- the relationship to check between thefieldValueand thewhenValueisCaseSensitive- whether string comparison will be carried out in a case sensitive fashiondateTimeService- used to convert strings to dates- Returns:
- true if the value matches the constraint
-
getInteger
converts the provided object into an integer- Parameters:
o- - the object to convert- Returns:
- the integer value
-
getLong
converts the provided object into a long- Parameters:
o- - the object to convert- Returns:
- the long value
-
getFloat
converts the provided object into an float- Parameters:
o- - the object to convert- Returns:
- the float value
-
getDouble
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 datedateTimeService- - used to convert strings to dates- Returns:
- a date object
- Throws:
IllegalArgumentException
-
getString
converts the provided object into a string- Parameters:
o- - the object to convert- Returns:
- the string value
-
getBoolean
converts the provided object into a boolean- Parameters:
o- - the object to convert- Returns:
- the boolean value
-
hasText
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
Checks whether the provided object is null, or if a String, List, Set or Map is empty.- Parameters:
value- - the object to check- Returns:
- true if the object is null or if a String, List, Set, or Map is 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 convertdataType- - the data type to convert intodateTimeService- - used to convert strings to dates- Returns:
- the converted value if null or successful, otherwise throws an exception
- Throws:
AttributeValidationException
-
isGreaterThan
checks whether the provided value is greater than the limit given- Type Parameters:
T-- Parameters:
value- - the object to checklimit- - the limit to use- Returns:
- one of the values in
ValidationUtils.Result
-
isGreaterThanOrEqual
checks whether the provided value is greater than or equal to the limit given- Type Parameters:
T-- Parameters:
value- - the object to checklimit- - the limit to use- Returns:
- one of the values in
ValidationUtils.Result
-
isLessThan
checks whether the provided value is less than the limit given- Type Parameters:
T-- Parameters:
value- - the object to checklimit- - the limit to use- Returns:
- one of the values in
ValidationUtils.Result
-
isLessThanOrEqual
checks whether the provided value is greater than the limit given- Type Parameters:
T-- Parameters:
value- - the object to checklimit- - the limit to use- Returns:
- one of the values in
ValidationUtils.Result
-
getPathTokens
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
-