|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.commons.cli2.validation.DateValidator
public class DateValidator
The 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
Field Summary | |
---|---|
private java.text.DateFormat[] |
formats
an array of permitted DateFormats |
private boolean |
isLenient
leniant parsing |
private java.util.Date |
maximum
maximum Date allowed i.e: a valid date occurs earlier than this date |
private java.util.Date |
minimum
minimum Date allowed i.e: a valid date occurs later than this date |
private static ResourceHelper |
resources
i18n |
Constructor Summary | |
---|---|
DateValidator()
Creates a Validator for the default date/time format |
|
DateValidator(java.text.DateFormat format)
Creates a Validator for the specified DateFormat. |
|
DateValidator(java.util.List formats)
Creates a Validator for the List of specified DateFormats. |
Method Summary | |
---|---|
static DateValidator |
getDateInstance()
Creates a Validator for dates. |
static DateValidator |
getDateTimeInstance()
Creates a Validator for date/times |
java.text.DateFormat[] |
getFormats()
Gets the date formats permitted. |
java.util.Date |
getMaximum()
Returns the maximum date permitted. |
java.util.Date |
getMinimum()
Returns the minimum date permitted. |
static DateValidator |
getTimeInstance()
Creates a Validator for times. |
private boolean |
isDateEarlier(java.util.Date date)
Returns whether the specified Date is earlier than the minimum date. |
private boolean |
isDateLater(java.util.Date date)
Returns whether the specified Date is later than the maximum date. |
boolean |
isLenient()
Returns whether this validator uses lenient parsing. |
void |
setFormat(java.text.DateFormat format)
Sets the date format permitted. |
void |
setFormats(java.text.DateFormat[] formats)
Sets the date formats permitted. |
void |
setFormats(java.util.List formats)
Sets the date formats permitted. |
void |
setLenient(boolean lenient)
Sets whether this validator uses lenient parsing. |
void |
setMaximum(java.util.Date maximum)
Sets the maximum Date to the specified value. |
void |
setMinimum(java.util.Date minimum)
Sets the minimum Date to the specified value. |
void |
validate(java.util.List values)
Validate each String value in the specified List against this instances permitted DateFormats. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final ResourceHelper resources
private java.text.DateFormat[] formats
private java.util.Date minimum
private java.util.Date maximum
private boolean isLenient
Constructor Detail |
---|
public DateValidator()
public DateValidator(java.text.DateFormat format)
format
- a DateFormat which dates must conform topublic DateValidator(java.util.List formats)
formats
- a List of DateFormats which dates must conform toMethod Detail |
---|
public static DateValidator getDateInstance()
public static DateValidator getTimeInstance()
public static DateValidator getDateTimeInstance()
public void validate(java.util.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 java.util.Date getMaximum()
null
.public void setMaximum(java.util.Date maximum)
maximum
- the maximum Date permittedpublic java.util.Date getMinimum()
null
.public void setMinimum(java.util.Date minimum)
minimum
- the minimum Date permittedprivate boolean isDateLater(java.util.Date date)
date
- the Date to evaluate
date
is earlier than the maximum
dateprivate boolean isDateEarlier(java.util.Date date)
date
- the Date to evaluate
date
is earlier than the minimum
datepublic void setFormat(java.text.DateFormat format)
format
- the format to usepublic void setFormats(java.util.List formats)
formats
- the List of DateFormats to usepublic void setFormats(java.text.DateFormat[] formats)
formats
- the array of DateFormats to usepublic java.text.DateFormat[] getFormats()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |