jcmdline
Class DateTimeParam

java.lang.Object
  extended byjcmdline.AbstractParameter
      extended byjcmdline.DateTimeParam
All Implemented Interfaces:
Parameter

public class DateTimeParam
extends AbstractParameter

A parameter that accepts a date and time as its value.

The format for the date is taken from the strings ResourceBundle. The format for the time is "HH:mm:ss:SSS", where the seconds and/or milliseconds portion may be left off by the user, in which case they will be defaulted.

Sample Usage:

     DateTimeParam startTimeParam = 
         new DateTimeParam("startTime", 
                           "start time of report", 
                           DateTimeParam.REQUIRED);
     DateTimeParam endTimeParam = 
         new DateTimeParam("endTime", 
                           "end time of report", 
                           DateTimeParam.REQUIRED);
 
     // Seconds and millis for startTime will both be 0 by default.
     // Set the seconds and millis for the end of the report to be the end 
     // of a minute.
     endTimeParam.setDefaultSeconds(59);
     endTimeParam.setDefaultMilliSeconds(999);
 
     CmdLineHandler cl = new DefaultCmdLineHandler(
         "myreport", "generate activity report",
         new Parameter[] {}, 
         new Parameter[] { startTimeParam, endTimeParam });
     
     cl.parse();
 
     // Don't need to check isSet() because params are REQUIRED
     Date stTime = startTimeParam.getDate();
     Date enTime = endTimeParam.getDate();
     .
     .
  
This will result in a command line that may be executed as:
   myreport "09/23/59 10:12" "09/23/59 23:34"
  
or
   myreport "09/23/59 10:12:34:567" "09/23/59 23:34:34:567"
  

Version:
jcmdline Rel. 1.0.3 $Id: DateTimeParam.java,v 1.2 2002/12/07 14:22:06 lglawrence Exp $
Author:
Lynne Lawrence
See Also:
DateParam, TimeParam

Field Summary
 
Fields inherited from class jcmdline.AbstractParameter
acceptableValues, desc, hidden, ignoreRequired, multiValued, optional, optionLabel, set, tag, values
 
Fields inherited from interface jcmdline.Parameter
HIDDEN, MULTI_VALUED, OPTIONAL, PUBLIC, REQUIRED, SINGLE_VALUED
 
Constructor Summary
DateTimeParam(java.lang.String tag, java.lang.String desc)
          constructor - creates single-valued, optional, public parameter
DateTimeParam(java.lang.String tag, java.lang.String desc, boolean optional)
          constructor - creates single-valued, public parameter which will will be either optional or required, as specified.
DateTimeParam(java.lang.String tag, java.lang.String desc, boolean optional, boolean multiValued)
          constructor - creates a public parameter which will will be either optional or required, and/or multi-valued, as specified.
DateTimeParam(java.lang.String tag, java.lang.String desc, boolean optional, boolean multiValued, boolean hidden)
          constructor - creates a parameter which will will be either optional or required, single or multi-valued, and hidden or public as specified.
DateTimeParam(java.lang.String tag, java.lang.String desc, java.util.Date[] acceptableValues)
          constructor - creates a single-valued, optional, public, number parameter whose value must be one of the specified values.
DateTimeParam(java.lang.String tag, java.lang.String desc, java.util.Date[] acceptableValues, boolean optional)
          constructor - creates a single-valued, public, number parameter whose value must be one of the specified values, and which is required or optional, as specified.
DateTimeParam(java.lang.String tag, java.lang.String desc, java.util.Date[] acceptableValues, boolean optional, boolean multiValued)
          constructor - creates a public number parameter whose value must be one of the specified values, and which is required or optional and/or multi-valued, as specified.
DateTimeParam(java.lang.String tag, java.lang.String desc, java.util.Date[] acceptableValues, boolean optional, boolean multiValued, boolean hidden)
          constructor - creates a Parameter, all of whose options are specified.
 
Method Summary
 java.util.Date[] getAcceptableDates()
          Gets the acceptable values as Date objects.
 java.util.Date getDate()
          Returns the value of this Parameter as a java.util.Date object.
 java.util.Date[] getDates()
          Returns the values of this Parameter as java.util.Date objects.
 int getDefaultMilliSeconds()
          Gets the default millisecond value to use if not specified by the user.
 int getDefaultSeconds()
          Gets the seconds default to use if not specified by the user.
static java.lang.String getParseFormat()
          Gets the format used to parse the date/time values.
 void setAcceptableDates(java.util.Collection vals)
          Sets acceptable values for this Parameter.
 void setAcceptableDates(java.util.Date[] dates)
          Sets the values that will be acceptable for this Parameter using Date objects.
 void setAcceptableValues(java.util.Collection vals)
          Unsupported.
 void setAcceptableValues(java.lang.String[] vals)
          Unsupported.
 void setDefaultMilliSeconds(int defaultMilliSeconds)
          Sets the default millisecond value to use if not specified by the user.
 void setDefaultSeconds(int defaultSeconds)
          Sets the seconds default to use if not specified by the user.
 void validateValue(java.lang.String val)
          Verifies that value is valid for this entity - called by add/setValue(s)().
 
Methods inherited from class jcmdline.AbstractParameter
addValue, getAcceptableValues, getDesc, getIgnoreRequired, getOptionLabel, getTag, getValue, getValues, isHidden, isMultiValued, isOptional, isSet, setDesc, setHidden, setIgnoreRequired, setMultiValued, setOptional, setOptionLabel, setTag, setValue, setValues, setValues
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DateTimeParam

public DateTimeParam(java.lang.String tag,
                     java.lang.String desc)
constructor - creates single-valued, optional, public parameter

Parameters:
tag - a unique identifier for this parameter
desc - a description of the parameter, suitable for display in a usage statement
Throws:
java.lang.IllegalArgumentException - if tag or are invalid.
See Also:
setTag(), setDesc()

DateTimeParam

public DateTimeParam(java.lang.String tag,
                     java.lang.String desc,
                     boolean optional)
constructor - creates single-valued, public parameter which will will be either optional or required, as specified.

Parameters:
tag - a unique identifier for this parameter
desc - a description of the parameter, suitable for display in a usage statement
optional - OPTIONAL if optional, REQUIRED if required
Throws:
java.lang.IllegalArgumentException - if any of the specified parameters are invalid.
See Also:
setTag(), setDesc()

DateTimeParam

public DateTimeParam(java.lang.String tag,
                     java.lang.String desc,
                     boolean optional,
                     boolean multiValued)
constructor - creates a public parameter which will will be either optional or required, and/or multi-valued, as specified.

Parameters:
tag - a unique identifier for this parameter
desc - a description of the parameter, suitable for display in a usage statement
optional - OPTIONAL if optional, REQUIRED if required
multiValued - MULTI_VALUED if the parameter can accept multiple values, SINGLE_VALUED if the parameter can contain only a single value
Throws:
java.lang.IllegalArgumentException - if any of the specified parameters are invalid.
See Also:
setTag(), setDesc(), SINGLE_VALUED, MULTI_VALUED

DateTimeParam

public DateTimeParam(java.lang.String tag,
                     java.lang.String desc,
                     boolean optional,
                     boolean multiValued,
                     boolean hidden)
constructor - creates a parameter which will will be either optional or required, single or multi-valued, and hidden or public as specified.

Parameters:
tag - a unique identifier for this parameter
desc - a description of the parameter, suitable for display in a usage statement
optional - OPTIONAL if optional, REQUIRED if required
multiValued - MULTI_VALUED if the parameter can accept multiple values, SINGLE_VALUED if the parameter can contain only a single value
hidden - HIDDEN if parameter is not to be listed in the usage, PUBLIC otherwise.
Throws:
java.lang.IllegalArgumentException - if any of the specified parameters are invalid.
See Also:
setTag(), setDesc(), SINGLE_VALUED, MULTI_VALUED, HIDDEN, PUBLIC

DateTimeParam

public DateTimeParam(java.lang.String tag,
                     java.lang.String desc,
                     java.util.Date[] acceptableValues)
constructor - creates a single-valued, optional, public, number parameter whose value must be one of the specified values.

Parameters:
tag - the tag associated with this parameter
desc - a description of the parameter, suitable for display in a usage statement
acceptableValues - the acceptable values for the parameter
Throws:
java.lang.IllegalArgumentException - if any parameter is invalid.
See Also:
setTag(), setDesc(), setAcceptableDates()

DateTimeParam

public DateTimeParam(java.lang.String tag,
                     java.lang.String desc,
                     java.util.Date[] acceptableValues,
                     boolean optional)
constructor - creates a single-valued, public, number parameter whose value must be one of the specified values, and which is required or optional, as specified.

Parameters:
tag - the tag associated with this parameter
desc - a description of the parameter, suitable for display in a usage statement
acceptableValues - the acceptable values for the parameter
optional - OPTIONAL if optional, REQUIRED if required
Throws:
java.lang.IllegalArgumentException - if any parameter is invalid.
See Also:
setTag(), setDesc(), setAcceptableDates(), OPTIONAL, REQUIRED

DateTimeParam

public DateTimeParam(java.lang.String tag,
                     java.lang.String desc,
                     java.util.Date[] acceptableValues,
                     boolean optional,
                     boolean multiValued)
constructor - creates a public number parameter whose value must be one of the specified values, and which is required or optional and/or multi-valued, as specified.

Parameters:
tag - the tag associated with this parameter
desc - a description of the parameter, suitable for display in a usage statement
acceptableValues - the acceptable values for the parameter
optional - OPTIONAL if optional, REQUIRED if required
multiValued - MULTI_VALUED if the parameter can accept multiple values, SINGLE_VALUED if the parameter can contain only a single value
Throws:
java.lang.IllegalArgumentException - if any parameter is invalid.
See Also:
setTag(), setDesc(), setAcceptableDates(), OPTIONAL, REQUIRED, SINGLE_VALUED, MULTI_VALUED

DateTimeParam

public DateTimeParam(java.lang.String tag,
                     java.lang.String desc,
                     java.util.Date[] acceptableValues,
                     boolean optional,
                     boolean multiValued,
                     boolean hidden)
constructor - creates a Parameter, all of whose options are specified.

Parameters:
tag - the tag associated with this parameter
desc - a description of the parameter, suitable for display in a usage statement
acceptableValues - the acceptable values for the parameter
optional - OPTIONAL if optional, REQUIRED if required
multiValued - MULTI_VALUED if the parameter can accept multiple values, SINGLE_VALUED if the parameter can contain only a single value
hidden - HIDDEN if parameter is not to be listed in the usage, PUBLIC otherwise.
Throws:
java.lang.IllegalArgumentException - if any parameter is invalid.
See Also:
setTag(), setDesc(), setAcceptableDates(), OPTIONAL, REQUIRED, SINGLE_VALUED, MULTI_VALUED, HIDDEN, PUBLIC
Method Detail

validateValue

public void validateValue(java.lang.String val)
                   throws CmdLineException
Verifies that value is valid for this entity - called by add/setValue(s)().

Specified by:
validateValue in interface Parameter
Overrides:
validateValue in class AbstractParameter
Parameters:
val - the value to be validated
Throws:
CmdLineException - if value is not valid.

getDate

public java.util.Date getDate()
Returns the value of this Parameter as a java.util.Date object. Should there be more than one value for this Parameter, the first value will be returned.

Returns:
the value of this Parameter as a Date object

getDates

public java.util.Date[] getDates()
Returns the values of this Parameter as java.util.Date objects.

Returns:
The values of this Parameter as Date objects. Note the the return value may be an empty array if no values have been set.

setDefaultSeconds

public void setDefaultSeconds(int defaultSeconds)
Sets the seconds default to use if not specified by the user. This will default to 0 if never specified for a DateTimeParam object.

Parameters:
defaultSeconds - the seconds default to use if not specified by the user
See Also:
getDefaultSeconds()

getDefaultSeconds

public int getDefaultSeconds()
Gets the seconds default to use if not specified by the user. This will default to 0 if never specified for a DateTimeParam object.

Returns:
the seconds default to use if not specified by the user
See Also:
setDefaultSeconds()

setDefaultMilliSeconds

public void setDefaultMilliSeconds(int defaultMilliSeconds)
Sets the default millisecond value to use if not specified by the user. This will default to 0 if never specified for a DateTimeParam object.

Parameters:
defaultMilliSeconds - the default millisecond value to use if not specified by the user
See Also:
getDefaultMilliSeconds()

getDefaultMilliSeconds

public int getDefaultMilliSeconds()
Gets the default millisecond value to use if not specified by the user. This will default to 0 if never specified for a DateTimeParam object.

Returns:
the default millisecond value to use if not specified by the user
See Also:
setDefaultMilliSeconds()

getParseFormat

public static java.lang.String getParseFormat()
Gets the format used to parse the date/time values.

Returns:
the format used to parse the date/time values

setAcceptableDates

public void setAcceptableDates(java.util.Date[] dates)
Sets the values that will be acceptable for this Parameter using Date objects.

Parameters:
dates - an array of acceptable dates

getAcceptableDates

public java.util.Date[] getAcceptableDates()
Gets the acceptable values as Date objects.

Returns:
The acceptable values as an array of Date objects. Note that null is returned if acceptable values have not been set.

setAcceptableDates

public void setAcceptableDates(java.util.Collection vals)
Sets acceptable values for this Parameter.

Parameters:
vals - a Collection of java.util.Date objects representing the acceptable values.
Throws:
java.lang.ClassCastException - if any member of vals is not a Date object.

setAcceptableValues

public void setAcceptableValues(java.util.Collection vals)
Unsupported. This method is unsupported because, with the date format coming from a resource bundle, it is not reasonable to code string values for acceptable values - better to use Date objects.

Specified by:
setAcceptableValues in interface Parameter
Overrides:
setAcceptableValues in class AbstractParameter
Parameters:
vals - the new acceptable values
Throws:
UnsupportedOperationException;
See Also:
setAcceptableDates(Date[]), setAcceptableDates(Collection)

setAcceptableValues

public void setAcceptableValues(java.lang.String[] vals)
Unsupported. This method is unsupported because, with the date format coming from a resource bundle, it is not reasonable to code string values for acceptable values - better to use Date objects.

Specified by:
setAcceptableValues in interface Parameter
Overrides:
setAcceptableValues in class AbstractParameter
Parameters:
vals - the new acceptable values
Throws:
UnsupportedOperationException;
See Also:
setAcceptableDates(Date[]), setAcceptableDates(Collection)