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:
- 1.3.0
- See Also:
-
Constructor Summary
ConstructorDescriptionAbstractFormatValidator
(boolean strict) Constructs an instance with the specified strict setting. -
Method Summary
Modifier and TypeMethodDescriptionFormat an object into aString
using the default Locale.Format an object into aString
using the specified pattern.Format an object using the specified pattern and/orLocale
.protected String
Format a value with the specifiedFormat
.Format an object into aString
using the specified Locale.protected abstract Format
Returns aFormat
for the specified pattern and/orLocale
.boolean
isStrict()
Indicates whether validated values should adhere strictly to theFormat
used.boolean
Validate using the defaultLocale
.boolean
Validate using the specified pattern.abstract boolean
Validate using the specified pattern and/orLocale
.boolean
Validate using the specifiedLocale
.protected Object
Parse the value with the specifiedFormat
.protected abstract Object
processParsedValue
(Object value, Format formatter) Process the parsed value, performing any further validation and type conversion required.
-
Constructor Details
-
AbstractFormatValidator
Constructs an instance with the specified strict setting.- Parameters:
strict
-true
if strictFormat
parsing should be used.
-
-
Method Details
-
format
Format an object into a
String
using the default Locale.- Parameters:
value
- The value validation is being performed on.- Returns:
- The value formatted as a
String
.
-
format
Format a value with the specified
Format
.- Parameters:
value
- The value to be formatted.formatter
- The Format to use.- Returns:
- The formatted value.
-
format
Format an object into a
String
using the specified Locale.- Parameters:
value
- The value validation is being performed on.locale
- The locale to use for the Format.- Returns:
- The value formatted as a
String
.
-
format
Format an object into a
String
using the specified pattern.- Parameters:
value
- The value validation is being performed on.pattern
- The pattern used to format the value.- Returns:
- The value formatted as a
String
.
-
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
.
-
getFormat
Returns a
Format
for the specified pattern and/orLocale
.- Parameters:
pattern
- The pattern used to validate the value against ornull
to use the default for theLocale
.locale
- The locale to use for the currency format, system default if null.- Returns:
- The
NumberFormat
to created.
-
isStrict
Indicates whether validated values should adhere strictly to the
Format
used.Typically implementations of
Format
ignore invalid characters at the end of the value and just stop parsing. For example parsing a date value of01/01/20x0
using a pattern ofdd/MM/yyyy
will result in a year of20
ifstrict
is set tofalse
, whereas settingstrict
totrue
will cause this value to fail validation.- Returns:
true
if strictFormat
parsing should be used.
-
isValid
Validate using the default
Locale
.- Parameters:
value
- The value validation is being performed on.- Returns:
true
if the value is valid.
-
isValid
Validate using the specified
Locale
.- Parameters:
value
- The value validation is being performed on.locale
- The locale to use for the Format, defaults to the default- Returns:
true
if the value is valid.
-
isValid
Validate using the specified pattern.
- Parameters:
value
- The value validation is being performed on.pattern
- The pattern used to validate the value against.- Returns:
true
if the value is valid.
-
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:
true
if the value is valid.
-
parse
Parse the value with the specified
Format
.- Parameters:
value
- The value to be parsed.formatter
- The Format to parse the value with.- Returns:
- The parsed value if valid or
null
if invalid.
-
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
null
if invalid.
-