Skip to content

Commit dd78531

Browse files
author
Robert James Oxspring
committed
The array of permitted formats is not mutable
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/cli/trunk@130083 13f79535-47bb-0310-9956-ffa450edef68
1 parent c082cca commit dd78531

1 file changed

Lines changed: 43 additions & 4 deletions

File tree

src/java/org/apache/commons/cli2/validation/DateValidator.java

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
public class DateValidator implements Validator {
3030

3131
/** an array of permitted DateFormats */
32-
private final DateFormat[] formats;
32+
private DateFormat[] formats;
3333

3434
/** minimum Date allowed i.e: a valid date occurs later than this date */
3535
private Date minimum;
@@ -78,7 +78,7 @@ public DateValidator() {
7878
* a DateFormat which dates must conform to
7979
*/
8080
public DateValidator(final DateFormat format) {
81-
this.formats = new DateFormat[] { format };
81+
setFormat(format);
8282
}
8383

8484
/**
@@ -88,8 +88,7 @@ public DateValidator(final DateFormat format) {
8888
* a List of DateFormats which dates must conform to
8989
*/
9090
public DateValidator(final List formats) {
91-
this.formats =
92-
(DateFormat[])formats.toArray(new DateFormat[formats.size()]);
91+
setFormats(formats);
9392
}
9493

9594
/**
@@ -210,4 +209,44 @@ private boolean isDateLater(Date date) {
210209
private boolean isDateEarlier(Date date) {
211210
return minimum != null && date.getTime() < minimum.getTime();
212211
}
212+
213+
/**
214+
* Sets the date format permitted.
215+
*
216+
* @param format
217+
* the format to use
218+
*/
219+
public void setFormat(final DateFormat format) {
220+
formats = new DateFormat[]{format};
221+
}
222+
223+
/**
224+
* Sets the date formats permitted.
225+
*
226+
* @param formats
227+
* the List of DateFormats to use
228+
*/
229+
public void setFormats(final List formats) {
230+
setFormats((DateFormat[])formats.toArray(new DateFormat[formats.size()]));
231+
}
232+
233+
/**
234+
* Sets the date formats permitted.
235+
*
236+
* @param formats
237+
* the array of DateFormats to use
238+
*/
239+
public void setFormats(final DateFormat[] formats) {
240+
this.formats = formats;
241+
}
242+
243+
/**
244+
* Gets the date formats permitted.
245+
*
246+
* @return the permitted formats
247+
*/
248+
public DateFormat[] getFormats() {
249+
return this.formats;
250+
}
251+
213252
}

0 commit comments

Comments
 (0)