phonebill.util
Class Parameters

java.lang.Object
  |
  +--phonebill.util.Parameters

public class Parameters
extends java.lang.Object

This class provides program parameter handling.


Inner Class Summary
 class Parameters.Value
          This inner class encapsulates the properties and value of a command line parameter.
 
Field Summary
protected  java.text.DateFormat df
          The date parser
protected  java.lang.String longPrefix
          The prefix for long parameters.
protected  java.text.NumberFormat nf
          The number parser
protected  Parameters.Value[] parameters
          The parameter properties and values.
protected  java.lang.String shortPrefix
          The prefix for short parameters.
static int T_BOOLEAN
          A constant to signify a boolean parameter.
static int T_DATE
          A constant to signify a date parameter.
static int T_FILE
          A constant to signify a file path.
static int T_NUMERIC
          A constant to signify a numeric parameter.
static int T_STRING
          A constant to signify a string parameter.
 
Constructor Summary
Parameters()
          Constructs an empty Parameters object.
Parameters(int count)
          Constructs a Parameters object with ready made space for count values.
Parameters(Parameters.Value[] properties)
          Constructs a Parameters object used to parse parameters.
 
Method Summary
 boolean addParameter(Parameters.Value value)
          Add a new parameter definition to this object
 boolean calc(java.lang.String[] commandLine)
          Read the command line.
 void dump()
          Dumps the contents of this object to the Out debug with level 3.
 Parameters.Value getParameter(java.lang.String name)
          Returns the parameter value by long name.
 Parameters.Value getParameter(java.lang.String name, boolean nameIsLong)
          Returns the parameter value by name.
 java.lang.String[] getPrefixes()
          Returns the current parameter prefixes.
 void setDateParser(java.text.DateFormat df)
          Sets the DateFormat object to be used for parsing dates.
 void setNumberParser(java.text.NumberFormat nf)
          Sets the NumberFormat object to be used for parsing numbers.
 void setPrefixes(java.lang.String shortPrefix, java.lang.String longPrefix)
          Changes the parameter prefixes.
 java.lang.String toString()
          Returns a textual description of this object.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

shortPrefix

protected java.lang.String shortPrefix
The prefix for short parameters.

longPrefix

protected java.lang.String longPrefix
The prefix for long parameters.

df

protected java.text.DateFormat df
The date parser

nf

protected java.text.NumberFormat nf
The number parser

parameters

protected Parameters.Value[] parameters
The parameter properties and values.

T_STRING

public static final int T_STRING
A constant to signify a string parameter. Saved as java.lang.String.

T_NUMERIC

public static final int T_NUMERIC
A constant to signify a numeric parameter. Saved as a subclass of java.lang.Number.

T_BOOLEAN

public static final int T_BOOLEAN
A constant to signify a boolean parameter. Saved as java.lang.Boolean.

T_DATE

public static final int T_DATE
A constant to signify a date parameter. Saved as java.util.Date.

T_FILE

public static final int T_FILE
A constant to signify a file path. Saved as java.io.File.
Constructor Detail

Parameters

public Parameters()
Constructs an empty Parameters object.

Parameters

public Parameters(int count)
Constructs a Parameters object with ready made space for count values.

Parameters

public Parameters(Parameters.Value[] properties)
Constructs a Parameters object used to parse parameters.
Parameters:
properties - the parameter properties.
Method Detail

calc

public boolean calc(java.lang.String[] commandLine)
Read the command line.
Parameters:
commandLine - the complete command line to fill into this parameter list.

addParameter

public boolean addParameter(Parameters.Value value)
Add a new parameter definition to this object
Parameters:
value - the new parameter definition.

getParameter

public Parameters.Value getParameter(java.lang.String name)
Returns the parameter value by long name.
Parameters:
name - the long name of the parameter.

getParameter

public Parameters.Value getParameter(java.lang.String name,
                                     boolean nameIsLong)
Returns the parameter value by name. The current parameter prefix is removed from the name.
Parameters:
name - the name of the parameter.
nameIsLong - true if name is the long name.

getPrefixes

public java.lang.String[] getPrefixes()
Returns the current parameter prefixes.

setPrefixes

public void setPrefixes(java.lang.String shortPrefix,
                        java.lang.String longPrefix)
Changes the parameter prefixes.
Parameters:
shortPrefix - The new prefix for short parameters. A null value becomes "".
longPrefix - The new prefix for long parameters. A null value becomes "".

setDateParser

public void setDateParser(java.text.DateFormat df)
Sets the DateFormat object to be used for parsing dates.
Parameters:
df - The new parser. Null values are ignored.

setNumberParser

public void setNumberParser(java.text.NumberFormat nf)
Sets the NumberFormat object to be used for parsing numbers.
Parameters:
nf - The new parser. Null values are ignored.

dump

public void dump()
Dumps the contents of this object to the Out debug with level 3.

toString

public java.lang.String toString()
Returns a textual description of this object.
Overrides:
toString in class java.lang.Object