net.dpml.cli.validation
Class DateValidator
java.lang.Object
net.dpml.cli.validation.DateValidator
- Validator
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
java.text.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
java.text.DateFormat
).
DateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");
...
ArgumentBuilder builder = new ArgumentBuilder();
Argument time =
builder.withName("time");
.withValidator(new DateValidator(timeFormat));
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.
|
DateValidator
public DateValidator()
Creates a Validator for the default date/time format
DateValidator
public DateValidator(DateFormat format)
Creates a Validator for the specified DateFormat.
format
- a DateFormat which dates must conform to
DateValidator
public DateValidator(List formats)
Creates a Validator for the List of specified DateFormats.
formats
- a List of DateFormats which dates must conform to
getFormats
public DateFormat[] getFormats()
Gets the date formats permitted.
getMaximum
public Date getMaximum()
Returns the maximum date permitted.
- Date the maximum date permitted. If no maximum date has been
specified then return
null
.
getMinimum
public Date getMinimum()
Returns the minimum date permitted.
- Date the minimum date permitted. If no minimum date has been
specified then return
null
.
isLeniant
public boolean isLeniant()
Return the leaniant flag.
setFormat
public void setFormat(DateFormat format)
Sets the date format permitted.
format
- the format to use
setFormats
public void setFormats(DateFormat[] formats)
Sets the date formats permitted.
formats
- the array of DateFormats to use
setFormats
public void setFormats(List formats)
Sets the date formats permitted.
formats
- the List of DateFormats to use
setLeniant
public void setLeniant(boolean lenient)
Set the leaniant flag.
lenient
- true if leniant
setMaximum
public void setMaximum(Date maximum)
Sets the maximum Date to the specified value.
maximum
- the maximum Date permitted
setMinimum
public void setMinimum(Date minimum)
Sets the minimum Date to the specified value.
minimum
- the minimum Date permitted
validate
public void validate(List values)
throws InvalidArgumentException
Validate each String value in the specified List against this instances
permitted DateFormats.
If a value is valid then it's String
value in the list is
replaced with it's Date
value.
- validate in interface Validator
values
- the list of values to validate
net.dpml.cli.validation.Validator.validate(java.util.List)