public class DateValidator extends Object implements Validator
DateValidator
validates the argument values
are date or time value(s).
The following example shows how to validate that
an argument value(s) is a Date of the following
type: d/M/yy (see DateFormat
).
DateFormat date = new SimpleDateFormat("d/M/yy"); ... ArgumentBuilder builder = new ArgumentBuilder(); Argument dateFormat = builder.withName("date"); .withValidator(new DateValidator(dateFormat));The following example shows how to validate that an argument value(s) is a time of the following type: HH:mm:ss (see
DateFormat
).
DateFormat timeFormat = new SimpleDateFormat("HH:mm:ss"); ... ArgumentBuilder builder = new ArgumentBuilder(); Argument time = builder.withName("time"); .withValidator(new DateValidator(timeFormat));
DateFormat
Constructor and Description |
---|
DateValidator()
Creates a Validator for the default date/time format
|
DateValidator(DateFormat format)
Creates a Validator for the specified DateFormat.
|
DateValidator(List formats)
Creates a Validator for the List of specified DateFormats.
|
Modifier and Type | Method and Description |
---|---|
static DateValidator |
getDateInstance()
Creates a Validator for dates.
|
static DateValidator |
getDateTimeInstance()
Creates a Validator for date/times
|
DateFormat[] |
getFormats()
Gets the date formats permitted.
|
Date |
getMaximum()
Returns the maximum date permitted.
|
Date |
getMinimum()
Returns the minimum date permitted.
|
static DateValidator |
getTimeInstance()
Creates a Validator for times.
|
boolean |
isLenient()
Returns whether this validator uses lenient parsing.
|
void |
setFormat(DateFormat format)
Sets the date format permitted.
|
void |
setFormats(DateFormat[] formats)
Sets the date formats permitted.
|
void |
setFormats(List formats)
Sets the date formats permitted.
|
void |
setLenient(boolean lenient)
Sets whether this validator uses lenient parsing.
|
void |
setMaximum(Date maximum)
Sets the maximum Date to the specified value.
|
void |
setMinimum(Date minimum)
Sets the minimum Date to the specified value.
|
void |
validate(List values)
Validate each String value in the specified List against this instances
permitted DateFormats.
|
public DateValidator()
public DateValidator(DateFormat format)
format
- a DateFormat which dates must conform topublic DateValidator(List formats)
formats
- a List of DateFormats which dates must conform topublic static DateValidator getDateInstance()
public static DateValidator getTimeInstance()
public static DateValidator getDateTimeInstance()
public void validate(List values) throws InvalidArgumentException
String
value in the list is
replaced with it's Date
value.validate
in interface Validator
values
- The values to validate.InvalidArgumentException
- If any of the
specified values are not valid.Validator.validate(java.util.List)
public void setLenient(boolean lenient)
lenient
- whether this validator uses lenient parsingpublic boolean isLenient()
public Date getMaximum()
null
.public void setMaximum(Date maximum)
maximum
- the maximum Date permittedpublic Date getMinimum()
null
.public void setMinimum(Date minimum)
minimum
- the minimum Date permittedpublic void setFormat(DateFormat format)
format
- the format to usepublic void setFormats(List formats)
formats
- the List of DateFormats to usepublic void setFormats(DateFormat[] formats)
formats
- the array of DateFormats to usepublic DateFormat[] getFormats()
Copyright © 2002-2013 The Apache Software Foundation. All Rights Reserved.