Package org.apache.commons.validator
Class GenericTypeValidator
- java.lang.Object
-
- org.apache.commons.validator.GenericTypeValidator
-
- All Implemented Interfaces:
java.io.Serializable
public class GenericTypeValidator extends java.lang.Object implements java.io.SerializableThis class contains basic methods for performing validations that return the correctly typed class based on the validation performed.- Version:
- $Revision: 1649191 $
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private static org.apache.commons.logging.LogLOGprivate static longserialVersionUID
-
Constructor Summary
Constructors Constructor Description GenericTypeValidator()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.ByteformatByte(java.lang.String value)Checks if the value can safely be converted to a byte primitive.static java.lang.ByteformatByte(java.lang.String value, java.util.Locale locale)Checks if the value can safely be converted to a byte primitive.static java.lang.LongformatCreditCard(java.lang.String value)Checks if the field is a valid credit card number.static java.util.DateformatDate(java.lang.String value, java.lang.String datePattern, boolean strict)Checks if the field is a valid date.static java.util.DateformatDate(java.lang.String value, java.util.Locale locale)Checks if the field is a valid date.static java.lang.DoubleformatDouble(java.lang.String value)Checks if the value can safely be converted to a double primitive.static java.lang.DoubleformatDouble(java.lang.String value, java.util.Locale locale)Checks if the value can safely be converted to a double primitive.static java.lang.FloatformatFloat(java.lang.String value)Checks if the value can safely be converted to a float primitive.static java.lang.FloatformatFloat(java.lang.String value, java.util.Locale locale)Checks if the value can safely be converted to a float primitive.static java.lang.IntegerformatInt(java.lang.String value)Checks if the value can safely be converted to a int primitive.static java.lang.IntegerformatInt(java.lang.String value, java.util.Locale locale)Checks if the value can safely be converted to an int primitive.static java.lang.LongformatLong(java.lang.String value)Checks if the value can safely be converted to a long primitive.static java.lang.LongformatLong(java.lang.String value, java.util.Locale locale)Checks if the value can safely be converted to a long primitive.static java.lang.ShortformatShort(java.lang.String value)Checks if the value can safely be converted to a short primitive.static java.lang.ShortformatShort(java.lang.String value, java.util.Locale locale)Checks if the value can safely be converted to a short primitive.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
LOG
private static final org.apache.commons.logging.Log LOG
-
-
Method Detail
-
formatByte
public static java.lang.Byte formatByte(java.lang.String value)
Checks if the value can safely be converted to a byte primitive.- Parameters:
value- The value validation is being performed on.- Returns:
- the converted Byte value.
-
formatByte
public static java.lang.Byte formatByte(java.lang.String value, java.util.Locale locale)Checks if the value can safely be converted to a byte primitive.- Parameters:
value- The value validation is being performed on.locale- The locale to use to parse the number (system default if null)- Returns:
- the converted Byte value.
-
formatShort
public static java.lang.Short formatShort(java.lang.String value)
Checks if the value can safely be converted to a short primitive.- Parameters:
value- The value validation is being performed on.- Returns:
- the converted Short value.
-
formatShort
public static java.lang.Short formatShort(java.lang.String value, java.util.Locale locale)Checks if the value can safely be converted to a short primitive.- Parameters:
value- The value validation is being performed on.locale- The locale to use to parse the number (system default if null)- Returns:
- the converted Short value.
-
formatInt
public static java.lang.Integer formatInt(java.lang.String value)
Checks if the value can safely be converted to a int primitive.- Parameters:
value- The value validation is being performed on.- Returns:
- the converted Integer value.
-
formatInt
public static java.lang.Integer formatInt(java.lang.String value, java.util.Locale locale)Checks if the value can safely be converted to an int primitive.- Parameters:
value- The value validation is being performed on.locale- The locale to use to parse the number (system default if null)- Returns:
- the converted Integer value.
-
formatLong
public static java.lang.Long formatLong(java.lang.String value)
Checks if the value can safely be converted to a long primitive.- Parameters:
value- The value validation is being performed on.- Returns:
- the converted Long value.
-
formatLong
public static java.lang.Long formatLong(java.lang.String value, java.util.Locale locale)Checks if the value can safely be converted to a long primitive.- Parameters:
value- The value validation is being performed on.locale- The locale to use to parse the number (system default if null)- Returns:
- the converted Long value.
-
formatFloat
public static java.lang.Float formatFloat(java.lang.String value)
Checks if the value can safely be converted to a float primitive.- Parameters:
value- The value validation is being performed on.- Returns:
- the converted Float value.
-
formatFloat
public static java.lang.Float formatFloat(java.lang.String value, java.util.Locale locale)Checks if the value can safely be converted to a float primitive.- Parameters:
value- The value validation is being performed on.locale- The locale to use to parse the number (system default if null)- Returns:
- the converted Float value.
-
formatDouble
public static java.lang.Double formatDouble(java.lang.String value)
Checks if the value can safely be converted to a double primitive.- Parameters:
value- The value validation is being performed on.- Returns:
- the converted Double value.
-
formatDouble
public static java.lang.Double formatDouble(java.lang.String value, java.util.Locale locale)Checks if the value can safely be converted to a double primitive.- Parameters:
value- The value validation is being performed on.locale- The locale to use to parse the number (system default if null)- Returns:
- the converted Double value.
-
formatDate
public static java.util.Date formatDate(java.lang.String value, java.util.Locale locale)Checks if the field is a valid date.The
Localeis used withjava.text.DateFormat. TheDateFormat.setLenient(boolean)method is set tofalsefor all.- Parameters:
value- The value validation is being performed on.locale- The Locale to use to parse the date (system default if null)- Returns:
- the converted Date value.
-
formatDate
public static java.util.Date formatDate(java.lang.String value, java.lang.String datePattern, boolean strict)Checks if the field is a valid date.The pattern is used with
java.text.SimpleDateFormat. If strict is true, then the length will be checked so '2/12/1999' will not pass validation with the format 'MM/dd/yyyy' because the month isn't two digits. TheDateFormat.setLenient(boolean)method is set tofalsefor all.- Parameters:
value- The value validation is being performed on.datePattern- The pattern passed toSimpleDateFormat.strict- Whether or not to have an exact match of the datePattern.- Returns:
- the converted Date value.
-
formatCreditCard
public static java.lang.Long formatCreditCard(java.lang.String value)
Checks if the field is a valid credit card number.Reference Sean M. Burke's script.
- Parameters:
value- The value validation is being performed on.- Returns:
- the converted Credit Card number.
-
-