Class AbstractFormatValidator
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
AbstractCalendarValidator, AbstractNumberValidator
Abstract class for Format based Validation.
This is a base class for building Date and Number Validators using format parsing.
- Since:
- Validator 1.3.0
- Version:
- $Revision: 1649191 $
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final longprivate final boolean -
Constructor Summary
ConstructorsConstructorDescriptionAbstractFormatValidator(boolean strict) Construct an instance with the specified strict setting. -
Method Summary
Modifier and TypeMethodDescriptionFormat an object into aStringusing the default Locale.Format an object into aStringusing the specified pattern.Format an object using the specified pattern and/orLocale.protected StringFormat a value with the specifiedFormat.Format an object into aStringusing the specified Locale.protected abstract FormatReturns aFormatfor the specified pattern and/orLocale.booleanisStrict()Indicates whether validated values should adhere strictly to theFormatused.booleanValidate using the defaultLocale.booleanValidate using the specified pattern.abstract booleanValidate using the specified pattern and/orLocale.booleanValidate using the specifiedLocale.protected ObjectParse the value with the specifiedFormat.protected abstract ObjectprocessParsedValue(Object value, Format formatter) Process the parsed value, performing any further validation and type conversion required.
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
strict
private final boolean strict
-
-
Constructor Details
-
AbstractFormatValidator
public AbstractFormatValidator(boolean strict) Construct an instance with the specified strict setting.- Parameters:
strict-trueif strictFormatparsing should be used.
-
-
Method Details
-
isStrict
public boolean isStrict()Indicates whether validated values should adhere strictly to the
Formatused.Typically implementations of
Formatignore invalid characters at the end of the value and just stop parsing. For example parsing a date value of01/01/20x0using a pattern ofdd/MM/yyyywill result in a year of20ifstrictis set tofalse, whereas settingstricttotruewill cause this value to fail validation.- Returns:
trueif strictFormatparsing should be used.
-
isValid
Validate using the default
Locale.- Parameters:
value- The value validation is being performed on.- Returns:
trueif the value is valid.
-
isValid
-
isValid
-
isValid
Validate using the specified pattern and/or
Locale.- Parameters:
value- The value validation is being performed on.pattern- The pattern used to format the value.locale- The locale to use for the Format, defaults to the default- Returns:
trueif the value is valid.
-
format
-
format
-
format
-
format
Format an object using the specified pattern and/or
Locale.- Parameters:
value- The value validation is being performed on.pattern- The pattern used to format the value.locale- The locale to use for the Format.- Returns:
- The value formatted as a
String.
-
format
-
parse
-
processParsedValue
Process the parsed value, performing any further validation and type conversion required.
- Parameters:
value- The parsed object created.formatter- The Format used to parse the value with.- Returns:
- The parsed value converted to the appropriate type
if valid or
nullif invalid.
-
getFormat
Returns a
Formatfor the specified pattern and/orLocale.- Parameters:
pattern- The pattern used to validate the value against ornullto use the default for theLocale.locale- The locale to use for the currency format, system default if null.- Returns:
- The
NumberFormatto created.
-