jcmdline
Class DateParam

java.lang.Object
  extended by jcmdline.AbstractParameter<java.util.Date>
      extended by jcmdline.DateParam
All Implemented Interfaces:
Parameter<java.util.Date>

public class DateParam
extends AbstractParameter<java.util.Date>

A parameter that accepts a date as its value.

The format for the date is taken from the strings ResourceBundle.

Sample Usage:

     DateParam startDateParam = 
         new DateParam("startDate", 
                       "start date of report", 
                       DateParam.REQUIRED);
     DateParam endDateParam = 
         new DateParam("endDate", 
                       "end date of report", 
                       DateParam.REQUIRED);
 
     // Time for startDate will be the beginning of the day by default.
     // Set the time for the end of the report to be the end of the day.
     endDateParam.setDefaultTime(23, 59, 58, 999);
 
     CmdLineHandler cl = new DefaultCmdLineHandler(
         "myreport", "report of activity over days",
         new Parameter[] {}, 
         new Parameter[] { startDateParam, endDateParam });
     
     cl.parse();
 
     // Don't need to check isSet() because params are REQUIRED
     Date stDate = startDateParam.getValue();
     Date enDate = endDateParam.getValue();
     .
     .
 

Version:
jcmdline Rel. 2.0.0 $Id: DateParam.java,v 1.2 2002/12/07 14:22:06 lglawrence Exp $
Author:
Lynne Lawrence
See Also:
DateTimeParam, 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
DateParam(java.lang.String tag, java.lang.String desc)
          constructor - creates single-valued, optional, public parameter
DateParam(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.
DateParam(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.
DateParam(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.
DateParam(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.
DateParam(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.
DateParam(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.
DateParam(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 convertValue(java.lang.String val)
          Converts a String value to the type associated with the Parameter.
 int[] getDefaultTime()
          Gets default values for the time component used to generate the Date value.
 void setDefaultTime(int h, int m, int s, int ms)
          Sets default values for the time component used to generate the Date value.
 
Methods inherited from class jcmdline.AbstractParameter
addStringValue, addValue, getAcceptableValues, getDesc, getIgnoreRequired, getOptionLabel, getTag, getValue, getValues, isHidden, isMultiValued, isOptional, isSet, setAcceptableValues, setAcceptableValues, setDesc, setHidden, setIgnoreRequired, setMultiValued, setOptional, setOptionLabel, setTag, setValue, setValues, setValues, validateValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DateParam

public DateParam(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()

DateParam

public DateParam(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()

DateParam

public DateParam(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

DateParam

public DateParam(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

DateParam

public DateParam(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(), setAcceptableValues()

DateParam

public DateParam(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(), setAcceptableValues(), OPTIONAL, REQUIRED

DateParam

public DateParam(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(), setAcceptableValues(), OPTIONAL, REQUIRED, SINGLE_VALUED, MULTI_VALUED

DateParam

public DateParam(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(), setAcceptableValues(), OPTIONAL, REQUIRED, SINGLE_VALUED, MULTI_VALUED, HIDDEN, PUBLIC
Method Detail

convertValue

public java.util.Date convertValue(java.lang.String val)
                            throws CmdLineException
Description copied from class: AbstractParameter
Converts a String value to the type associated with the Parameter. All non-abstract subclasses must implement this method.

Specified by:
convertValue in class AbstractParameter<java.util.Date>
Parameters:
val - the String value of the Parameter
Returns:
the parameter value converted to the Object type with which the Parameter is associated
Throws:
CmdLineException - if the conversion cannot be made
See Also:
AbstractParameter.convertValue(java.lang.String)

getDefaultTime

public int[] getDefaultTime()
Gets default values for the time component used to generate the Date value.

Returns:
a 4 element int array, where the elements are the default hours, minutes, seconds, and milliseconds, in that order

setDefaultTime

public void setDefaultTime(int h,
                           int m,
                           int s,
                           int ms)
Sets default values for the time component used to generate the Date value.

Parameters:
h - the hours - 0-23 - defaults to 0
m - the minutes - 0-59 - defaults to 0
s - the seconds - 0-59 - defaults to 0
ms - the milliseconds - 0-999 - defaults to 0
Throws:
java.lang.IllegalArgumentException - if any of the parameters are in error.