joptsimple.util
Class DateConverter

java.lang.Object
  extended by joptsimple.util.DateConverter
All Implemented Interfaces:
ValueConverter<Date>

public class DateConverter
extends Object
implements ValueConverter<Date>

Converts values to Dates using a DateFormat object.

Version:
$Id: DateConverter.java,v 1.4 2009/04/04 01:24:26 pholser Exp $
Author:
Paul Holser

Constructor Summary
DateConverter(DateFormat formatter)
          Creates a converter that uses the given date formatter/parser.
 
Method Summary
 Date convert(String value)
          Converts the given string value into a Java type.
static DateConverter datePattern(String pattern)
          Creates a converter that uses a SimpleDateFormat with the given date/time pattern.
 String valuePattern()
          Gives a string that describes the pattern of the values this converter expects, if any.
 Class<Date> valueType()
          Gives the class of the type of values this converter converts to.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DateConverter

public DateConverter(DateFormat formatter)
Creates a converter that uses the given date formatter/parser.

Parameters:
formatter - the formatter/parser to use
Throws:
NullPointerException - if formatter is null
Method Detail

datePattern

public static DateConverter datePattern(String pattern)
Creates a converter that uses a SimpleDateFormat with the given date/time pattern. The date formatter created is not lenient.

Parameters:
pattern - expected date/time pattern
Returns:
the new converter
Throws:
NullPointerException - if pattern is null
IllegalArgumentException - if pattern is invalid

convert

public Date convert(String value)
Converts the given string value into a Java type.

Specified by:
convert in interface ValueConverter<Date>
Parameters:
value - the string to convert
Returns:
the converted value

valueType

public Class<Date> valueType()
Gives the class of the type of values this converter converts to.

Specified by:
valueType in interface ValueConverter<Date>
Returns:
the target class for conversion

valuePattern

public String valuePattern()
Gives a string that describes the pattern of the values this converter expects, if any. For example, a date converter can respond with a date format string.

Specified by:
valuePattern in interface ValueConverter<Date>
Returns:
a value pattern, or null if there's nothing interesting here


© Copyright 2004-2009 Paul R. Holser, Jr. All rights reserved. Licensed under The MIT License. pholser@alumni.rice.edu