|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.pf.text.CommandLineArguments
public class CommandLineArguments
Utility class for easy evaluation of command line arguments.
| Constructor Summary | |
|---|---|
CommandLineArguments()
Initialize the new instance with no arguments. |
|
CommandLineArguments(java.lang.String[] args)
Initialize the new instance with an array of arguments. |
|
CommandLineArguments(java.lang.String[] args,
java.lang.String switchIndicator)
Initialize the new instance with an array of arguments and a prefix indicator for options |
|
| Method Summary | |
|---|---|
void |
addOption(java.lang.String option)
Adds the given option to the command line. |
void |
addOptionWithArgument(java.lang.String option,
java.lang.String argument)
Adds the given option to the command line. |
CommandLineArguments |
copy()
Returns a copy of this object, with all internal state being the same as in the original. |
java.lang.String |
getArgumentAt(int index)
Returns the argument at the specified index or null if the index is outside the bounds of the argument list. |
java.lang.String[] |
getArguments()
Returns a string array containing all arguments. |
java.lang.String |
getArgumentValue(java.lang.String option)
Returns the value following the specified option. |
java.lang.String |
getArgumentValue(java.lang.String option,
java.lang.String defaultValue)
Returns the value following the specified option. |
java.lang.String[] |
getArgumentValues(java.lang.String option)
Returns all values that are found for the specified option. |
java.lang.String[] |
getArgumentValues(java.lang.String option,
java.lang.String[] defaultValues)
Returns the values following the specified option. |
java.lang.String[] |
getOptionValues(java.lang.String option)
Returns all values after the given option which do NOT start with the configured switch indicator. |
java.lang.String |
getSwitchIndicator()
Returns the prefix which must preceed each command line switch (option). |
boolean |
isOptionSet(java.lang.String option)
Returns whether or not the specified option is set in the command line arguments. |
void |
removeOption(java.lang.String option)
Remove the specified option from the command line arguments. |
void |
removeOptionWithArgument(java.lang.String option)
Remove the specified option from the command line arguments. |
void |
setSwitchIndicator(java.lang.String newValue)
Sets the prefix which must preceed each command line swith. |
int |
size()
Returns the current number of argument |
java.lang.String |
toString()
Returns a String with all arguments separated by blanks |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public CommandLineArguments()
public CommandLineArguments(java.lang.String[] args)
args - The arguments of the command line
public CommandLineArguments(java.lang.String[] args,
java.lang.String switchIndicator)
args - The arguments of the command lineswitchIndicator - A prefix for options| Method Detail |
|---|
public java.lang.String toString()
toString in class java.lang.Objectpublic boolean isOptionSet(java.lang.String option)
Examples:
option - The option to be looked for
java.lang.IllegalArgumentException - If the given option is null
public java.lang.String getArgumentValue(java.lang.String option,
java.lang.String defaultValue)
getArgumentValue(String).
option - The option which indicates that the next argument is the desired valuedefaultValue - The default value to return if the option is not found
java.lang.IllegalArgumentException - If the given option is nullpublic java.lang.String getArgumentValue(java.lang.String option)
Examples:
Arguments: -v -f sample.xml -t
getArgumentValue( "-f" ) returns "sample.xml"
Arguments: -v -m -t
getArgumentValue( "-f" ) returns null
Arguments: -v -t -f
getArgumentValue( "-f" ) returns ""
Arguments: -v -f -t sample.xml
getArgumentValue( "-f" ) returns ""
Arguments: -v -x2000 -t
getArgumentValue( "-x" ) returns "2000"
Arguments: -v"first draft" -x -t
getArgumentValue( "-v" ) returns "first draft"
option - The option which indicates that the next argument is the desired value
java.lang.IllegalArgumentException - If the given option is nullpublic java.lang.String[] getArgumentValues(java.lang.String option)
Example:
Arguments: -v -x2000 -t -x 120 -xFM
getArgumentValues( "-x" ) returns { "2000", "120", "FM" }
option - The option which is the prefix for the desired values
java.lang.IllegalArgumentException - If the given option is null
public java.lang.String[] getArgumentValues(java.lang.String option,
java.lang.String[] defaultValues)
getArgumentValue(String, String).
option - The option which indicates that the next arguments are the desired valuesdefaultValues - The default values to return if the option is not found
java.lang.IllegalArgumentException - If the given option is nullpublic java.lang.String[] getOptionValues(java.lang.String option)
Example:
Arguments: -v -x 2000 south 30 west -t -f test.txt -Uc22
getOptionValues( "-x" ) returns { "2000", "south", "30", "west }
getOptionValues( "-v" ) returns String[0]
getOptionValues( "-f" ) returns { "test.txt" }
getOptionValues( "-M" ) returns null
option - The option which is the prefix for the desired values
java.lang.IllegalArgumentException - If the given option is nullpublic void addOption(java.lang.String option)
option - An option including the switch indicator if necessary (e.g. "-x")
java.lang.IllegalArgumentException - If the given option is null
public void addOptionWithArgument(java.lang.String option,
java.lang.String argument)
option - An option including the switch indicator if necessary (e.g. "-x")argument - The argument of the option
java.lang.IllegalArgumentException - If the given option or argument is nullpublic void removeOption(java.lang.String option)
option - The option to be removedpublic void removeOptionWithArgument(java.lang.String option)
option - The option to be removedpublic CommandLineArguments copy()
public java.lang.String getSwitchIndicator()
public void setSwitchIndicator(java.lang.String newValue)
public int size()
public java.lang.String[] getArguments()
public java.lang.String getArgumentAt(int index)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||