javatools.util
Class ArgumentProcessor

java.lang.Object
  |
  +--javatools.util.ArgumentProcessor

public class ArgumentProcessor
extends java.lang.Object

It's a class useful to process arguments passed via command line.


Constructor Summary
ArgumentProcessor()
          Creates new ArgumentProcessor
 
Method Summary
 void cleanValues()
          Turns all flags to FALSE and all values to empty strings
 java.lang.String getArgumentHelpText(int argPos, java.lang.String paramName)
          Returns the help text whose position is specified.
 java.lang.String getArgumentHelpText(java.lang.String argName, java.lang.String paramName)
          Returns the help text of an argument whose name is specified.
 java.lang.String getArgumentName(int argPos)
          Returns the name of an argument.
 int getArgumentPos(java.lang.String argName)
          Returns the position of an argument.
 java.lang.String getArgumentValue(int argPos)
          Returns the value of an argument whose position is specified.
 java.lang.String getArgumentValue(java.lang.String argName)
          Return the value of an argument whose name is specified.
 java.lang.String getFlagHelpText(int numFlag)
          Returns help text of a flag whose position is specified.
 java.lang.String getFlagHelpText(java.lang.String flagName)
          Returns help text of a flag whose name is specified.
 java.lang.String getFlagName(int numFlag)
          Returns the name of the flag.
 int getFlagPos(java.lang.String flagName)
          Returns the position of the flag.
 boolean getFlagValue(int flagPos)
          The value of a flag whose position is specified.
 boolean getFlagValue(java.lang.String flagName)
          Returns the value of a flag whose name is specified.
 int getNumArguments()
          Returns the number of arguments.
 int getNumFlags()
          Returns the number of flags.
 void processArguments(java.lang.String[] args)
          Process the command line parameters.
 void setArgumentHelpText(int argPos, java.lang.String helpText)
          Sets help text for an argument whose position is specified.
 void setArgumentHelpText(java.lang.String argName, java.lang.String helpText)
          Sets help text for an argument whose name is specified.
 void setArgumentName(int argPos, java.lang.String argName)
          Sets the name of an argument.
 void setArgumentValue(int argPos, java.lang.String argValue)
          Sets the value of an argument whose position is specified.
 void setArgumentValue(java.lang.String argName, java.lang.String argValue)
          Sets the value of an argument, whose name is specified.
 void setFlagHelpText(int numFlag, java.lang.String helpText)
          Sets help text for a flag whose position is specified.
 void setFlagHelpText(java.lang.String flagName, java.lang.String helpText)
          Sets help text for a flag whose name is specified.
 void setFlagName(int numFlag, java.lang.String flagName)
          Sets the name of a flag.
 void setFlagValue(int flagPos, boolean flagValue)
          Sets the value of a flag whose position is specified.
 void setFlagValue(java.lang.String flagName, boolean flagValue)
          Sets the value of a flag whose name is specified.
 void setNumArguments(int numArgs)
          Sets the number of arguments (parameters with different values, used with to strings in command lines).
 void setNumFlags(int numArgs)
          Sets the number of flags (parameters with with TRUE-FALSE values, used alone in command lines).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArgumentProcessor

public ArgumentProcessor()
Creates new ArgumentProcessor

Method Detail

setNumFlags

public void setNumFlags(int numArgs)
                 throws java.lang.IndexOutOfBoundsException
Sets the number of flags (parameters with with TRUE-FALSE values, used alone in command lines).

Parameters:
numArgs - Number of flags used.
Throws:
java.lang.IndexOutOfBoundsException - If numArgs is less than 1.

getNumFlags

public int getNumFlags()
Returns the number of flags.

Returns:
The number of flags used.

setNumArguments

public void setNumArguments(int numArgs)
                     throws java.lang.IndexOutOfBoundsException
Sets the number of arguments (parameters with different values, used with to strings in command lines).

Parameters:
numArgs - Number of arguments used.
Throws:
java.lang.IndexOutOfBoundsException - If numArgs is less than 1.

getNumArguments

public int getNumArguments()
Returns the number of arguments.

Returns:
The number of arguments used.

setFlagName

public void setFlagName(int numFlag,
                        java.lang.String flagName)
                 throws java.lang.IndexOutOfBoundsException
Sets the name of a flag.

Parameters:
numFlag - The number of the flag. It has to be between 0 and getNumFlags()-1.
flagName - The name of the flag.
Throws:
java.lang.IndexOutOfBoundsException - If numFlag is not valid.

getFlagName

public java.lang.String getFlagName(int numFlag)
                             throws java.lang.IndexOutOfBoundsException
Returns the name of the flag.

Parameters:
numFlag - The position of the flag. It has to be between 0 and getNumFlags()-1.
Returns:
The name of the flag.
Throws:
java.lang.IndexOutOfBoundsException - if numFlag is not valid.

getFlagPos

public int getFlagPos(java.lang.String flagName)
Returns the position of the flag.

Parameters:
flagName - The name of the interested flag.
Returns:
The position of the flag, if existing. It has to be between 0 and getNumFlags()-1.

setFlagValue

public void setFlagValue(java.lang.String flagName,
                         boolean flagValue)
Sets the value of a flag whose name is specified.

Parameters:
flagName - The name of the flag.
flagValue - The value of the flag.

setFlagValue

public void setFlagValue(int flagPos,
                         boolean flagValue)
                  throws java.lang.IndexOutOfBoundsException
Sets the value of a flag whose position is specified.

Parameters:
flagPos - Position of the flag. It has to be between 0 and getNumFlags()-1.
flagValue - The value of the flag.
Throws:
java.lang.IndexOutOfBoundsException - If flagPos is not valid.

getFlagValue

public boolean getFlagValue(java.lang.String flagName)
Returns the value of a flag whose name is specified.

Parameters:
flagName - The name of the flag.
Returns:
The value of the flag, if existing. False, otherwise.

getFlagValue

public boolean getFlagValue(int flagPos)
                     throws java.lang.IndexOutOfBoundsException
The value of a flag whose position is specified.

Parameters:
flagPos - The position of the flag. It has to be between 0 and getNumFlags()-1.
Returns:
The value of the flag, if existing.
Throws:
java.lang.IndexOutOfBoundsException - If flagPos is not valid.

setArgumentName

public void setArgumentName(int argPos,
                            java.lang.String argName)
                     throws java.lang.IndexOutOfBoundsException
Sets the name of an argument.

Parameters:
argPos - The position of the argument. It has to be between 0 and getNumArguments()-1.
argName - The name of the argument.
Throws:
java.lang.IndexOutOfBoundsException - if argPos is not valid.

getArgumentName

public java.lang.String getArgumentName(int argPos)
                                 throws java.lang.IndexOutOfBoundsException
Returns the name of an argument.

Parameters:
argPos - The position of the argument. It has to be between 0 and getNumArguments()-1.
Returns:
The name of the argument.
Throws:
java.lang.IndexOutOfBoundsException - If argPos is not valid.

getArgumentPos

public int getArgumentPos(java.lang.String argName)
Returns the position of an argument.

Parameters:
argName - The name of the argument.
Returns:
The position of the argument, if existing.

setArgumentValue

public void setArgumentValue(java.lang.String argName,
                             java.lang.String argValue)
Sets the value of an argument, whose name is specified.

Parameters:
argName - The name of the argument.
argValue - The value of the argument.

setArgumentValue

public void setArgumentValue(int argPos,
                             java.lang.String argValue)
                      throws java.lang.IndexOutOfBoundsException
Sets the value of an argument whose position is specified.

Parameters:
argPos - Position of the argument. It has to be between 0 and getNumArguments()-1.
argValue - Value of the argument.
Throws:
java.lang.IndexOutOfBoundsException - If argPos is not valid.

getArgumentValue

public java.lang.String getArgumentValue(java.lang.String argName)
Return the value of an argument whose name is specified.

Parameters:
argName - Name of the argument.
Returns:
Value of the argument.

getArgumentValue

public java.lang.String getArgumentValue(int argPos)
                                  throws java.lang.IndexOutOfBoundsException
Returns the value of an argument whose position is specified.

Parameters:
argPos - Position of the argument. It has to be between 0 and getNumArguments()-1.
Returns:
The value of the argument.
Throws:
java.lang.IndexOutOfBoundsException - If argPos is not valid.

cleanValues

public void cleanValues()
Turns all flags to FALSE and all values to empty strings


processArguments

public void processArguments(java.lang.String[] args)
Process the command line parameters.

Parameters:
args - The parameters passed via command line.

setFlagHelpText

public void setFlagHelpText(java.lang.String flagName,
                            java.lang.String helpText)
Sets help text for a flag whose name is specified.

Parameters:
flagName - The name of the flag.
helpText - The help text.

setFlagHelpText

public void setFlagHelpText(int numFlag,
                            java.lang.String helpText)
Sets help text for a flag whose position is specified.

Parameters:
numFlag - Position of the flag. It has to be between 0 and getNumFlags()-1.
helpText - The help text.

getFlagHelpText

public java.lang.String getFlagHelpText(java.lang.String flagName)
Returns help text of a flag whose name is specified.

Parameters:
flagName - The name of the flag.
Returns:
The help text.

getFlagHelpText

public java.lang.String getFlagHelpText(int numFlag)
Returns help text of a flag whose position is specified.

Parameters:
numFlag - The position of the flag. It has to be between 0 and getNumFlags()-1.
Returns:
The help text.

setArgumentHelpText

public void setArgumentHelpText(java.lang.String argName,
                                java.lang.String helpText)
Sets help text for an argument whose name is specified.

Parameters:
argName - The name of the argument.
helpText - The help text. Use "%P%" inside this string to represent the text which will be replaced with a given variable parameter name.

setArgumentHelpText

public void setArgumentHelpText(int argPos,
                                java.lang.String helpText)
Sets help text for an argument whose position is specified.

Parameters:
argPos - The position of the argument. It has to be between 0 and getNumArguments()-1.
helpText - The help text. Use "%P%" inside this string to represent the text which will be replaced with a given variable parameter name.

getArgumentHelpText

public java.lang.String getArgumentHelpText(java.lang.String argName,
                                            java.lang.String paramName)
Returns the help text of an argument whose name is specified.

Parameters:
argName - The name of the argument.
paramName - The variable parameter name replaced inside the help text instead of the substring "%P%".
Returns:
The help text.

getArgumentHelpText

public java.lang.String getArgumentHelpText(int argPos,
                                            java.lang.String paramName)
Returns the help text whose position is specified.

Parameters:
argPos - The position of the argument. It has to be between 0 and getNumArguments()-1.
paramName - The variable parameter name replaced inside the help text instead of the substring "%P%".
Returns:
The help text.