jcmdline
Class TimeParam

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

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

A parameter that accepts a time as its value.

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:

     TimeParam startTimeParam = 
         new TimeParam("startTime", 
                       "start time of report", 
                       TimeParam.REQUIRED);
     TimeParam endTimeParam = 
         new TimeParam("endTime", 
                       "end time of report", 
                       TimeParam.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.  The date portion will be the current day, which is 
     // the default.
     endTimeParam.setDefaultSeconds(59);
     endTimeParam.setDefaultMilliSeconds(999);
 
     CmdLineHandler cl = new DefaultCmdLineHandler(
         "myreport", "generate current activity report",
         new Parameter[] {}, 
         new Parameter[] { startTimeParam, endTimeParam });
     
     cl.parse();
 
     // Don't need to check isSet() because params are REQUIRED
     Date stTime = startTimeParam.getValue();
     Date enTime = endTimeParam.getValue();
     .
     .
 
This will result in a command line that may be executed as:
   myreport "10:12" "23:34"
 
or
   myreport "10:12:34:567" "23:34:34:567"
 

Version:
jcmdline Rel. 2.0.0 $Id: TimeParam.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
TimeParam(java.lang.String tag, java.lang.String desc)
          constructor - creates single-valued, optional, public parameter, with a default datePortion of the current day
TimeParam(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, with a default datePortion of the current day
TimeParam(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, with a default datePortion of the current day
TimeParam(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, with a default datePortion of the current day
TimeParam(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, with a default datePortion of the current day
TimeParam(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, with a default datePortion of the current day
TimeParam(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, with a default datePortion of the current day
TimeParam(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, with a default datePortion of the current day
 
Method Summary
 java.util.Date convertValue(java.lang.String strVal)
          Converts a String value to the type associated with the Parameter.
 java.util.Date getDatePortion()
           
 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.
 void setDatePortion(java.util.Date datePortion)
           
 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.util.Date val)
          This implementation compares the value to the acceptable values if any have been defined.
 
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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TimeParam

public TimeParam(java.lang.String tag,
                 java.lang.String desc)
constructor - creates single-valued, optional, public parameter, with a default datePortion of the current day

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

TimeParam

public TimeParam(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, with a default datePortion of the current day

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

TimeParam

public TimeParam(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, with a default datePortion of the current day

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

TimeParam

public TimeParam(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, with a default datePortion of the current day

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

TimeParam

public TimeParam(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, with a default datePortion of the current day

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

TimeParam

public TimeParam(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, with a default datePortion of the current day

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

TimeParam

public TimeParam(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, with a default datePortion of the current day

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

TimeParam

public TimeParam(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, with a default datePortion of the current day

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 strVal)
                            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:
strVal - 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)

getDatePortion

public java.util.Date getDatePortion()
Returns:
the datePortion

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 TimeParam object.

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

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 TimeParam object.

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

setDatePortion

public void setDatePortion(java.util.Date datePortion)
Parameters:
datePortion - the datePortion to set

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 TimeParam object.

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

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 TimeParam object.

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

validateValue

public void validateValue(java.util.Date val)
                   throws CmdLineException
Description copied from class: AbstractParameter
This implementation compares the value to the acceptable values if any have been defined.

Overrides:
validateValue in class AbstractParameter<java.util.Date>
Parameters:
val - the value to be validated
Throws:
CmdLineException - if there are acceptable values defined and the value is not one of them.
See Also:
AbstractParameter.validateValue(java.lang.Object)