bill.util
Class GetOpt
java.lang.Object
|
+--bill.util.GetOpt
- public class GetOpt
- extends Object
This class loosely imitates the functionality of the C get opt API.
It parses an array of command line arguments looking for the specified
list of switches, and, if requested, the switches' values.
Method Summary |
String |
getOption(char cSwitch)
Gets the value of the specified switch. |
String |
getOption(Character aSwitch)
Gets the value of the specified switch. |
boolean |
isOption(char cSwitch)
Checks if the specified switch was entered on the command line. |
boolean |
isOption(Character aSwitch)
Checks if the specified switch was entered on the command line. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
GetOpt
public GetOpt(String[] astrArgs,
String strSwitches)
- The class's creator. Note that switches can either have a value
associated with them (in which case they are specified with a colon
(:) after them) or not.
For example if my application takes two command line switches, a and b,
with a value required for a but not for b, the strSwitches parameter
would contain the string "a:b"
- Parameters:
astrArgs
- The array of arguments to parsestrSwitches
- The switches to look for
isOption
public boolean isOption(Character aSwitch)
- Checks if the specified switch was entered on the command line.
- Parameters:
aSwitch
- The option to look for- Returns:
true
if the switch was entered, false
otherwise.
isOption
public boolean isOption(char cSwitch)
- Checks if the specified switch was entered on the command line.
- Parameters:
cSwitch
- The option to look for- Returns:
true
if the switch was entered, false
otherwise.
getOption
public String getOption(Character aSwitch)
- Gets the value of the specified switch. Note that for options which
do not have a value, this method will return
null
.
- Parameters:
aSwitch
- The option to look for- Returns:
- The option's value if it exists and has one,
null
otherwise
getOption
public String getOption(char cSwitch)
- Gets the value of the specified switch. Note that for options which
do not have a value, this method will return
null
.
- Parameters:
cSwitch
- The option to look for- Returns:
- The option's value if it exists and has one,
null
otherwise