public class Options
extends java.lang.Object
| Constructor and Description |
|---|
Options(java.lang.String[] args,
java.lang.String[] specs)
Parse options.
|
| Modifier and Type | Method and Description |
|---|---|
void |
checkNoArguments()
Check that the number of non-option arguments is zero.
|
boolean |
contains(java.lang.String option)
Check if option is present.
|
java.lang.String |
get(java.lang.String option)
Return string option value.
|
java.lang.String |
get(java.lang.String option,
java.lang.String defaultValue)
Return string option value.
|
java.util.ArrayList<java.lang.String> |
getArguments()
Get remaining arguments that are not options.
|
double |
getDouble(java.lang.String option)
Parse double option.
|
double |
getDouble(java.lang.String option,
double defaultValue)
Parse double option.
|
int |
getInteger(java.lang.String option)
Parse integer option.
|
int |
getInteger(java.lang.String option,
int defaultValue)
Parse integer option.
|
int |
getInteger(java.lang.String option,
int defaultValue,
int min)
Parse integer option with range check.
|
int |
getInteger(java.lang.String option,
int defaultValue,
int min,
int max)
Parse integer option with range check.
|
long |
getLong(java.lang.String option)
Parse long integer option.
|
long |
getLong(java.lang.String option,
long defaultValue)
Parse long integer option.
|
void |
handleConfigOption()
Read options from a file given with the option "config".
|
static Options |
parse(java.lang.String[] args,
java.lang.String[] specs)
Creates a new Options instance from command line.
|
public Options(java.lang.String[] args,
java.lang.String[] specs)
throws ErrorMessage
args - Command line args from main methodspecs - Specification of allowed options. Contains option names
(without '-'). Options that need an argument must have a ':' appended.
The special argument '--' stops option parsing, all following
arguments are treated as non-option arguments.ErrorMessage - If options are not valid according to specs.public boolean contains(java.lang.String option)
public java.lang.String get(java.lang.String option)
option - The option key.public java.lang.String get(java.lang.String option,
java.lang.String defaultValue)
option - The option key.defaultValue - The default value.public java.util.ArrayList<java.lang.String> getArguments()
public void checkNoArguments()
throws ErrorMessage
ErrorMessage - If there are any non-option arguments.public double getDouble(java.lang.String option)
throws ErrorMessage
option - The option key.ErrorMessage - If option value is not a double.public double getDouble(java.lang.String option,
double defaultValue)
throws ErrorMessage
option - The option key.defaultValue - The default value.ErrorMessage - If option value is not a double.public int getInteger(java.lang.String option)
throws ErrorMessage
option - The option key.ErrorMessage - If option value is not an integer.public int getInteger(java.lang.String option,
int defaultValue)
throws ErrorMessage
option - The option key.defaultValue - The default value.ErrorMessage - If option value is not an integer.public int getInteger(java.lang.String option,
int defaultValue,
int min)
throws ErrorMessage
option - The option key.defaultValue - The default value.min - The minimum valid value.ErrorMessage - If option value is less than min.public int getInteger(java.lang.String option,
int defaultValue,
int min,
int max)
throws ErrorMessage
option - The option key.defaultValue - The default value.min - The minimum valid value.max - The maximum valid value.ErrorMessage - If option value is less than min or greater than
max.public long getLong(java.lang.String option)
throws ErrorMessage
option - The option key.ErrorMessage - If option value is not a long integer.public long getLong(java.lang.String option,
long defaultValue)
throws ErrorMessage
option - The option key.defaultValue - The default value.ErrorMessage - If option value is not a long integer.public void handleConfigOption()
throws ErrorMessage
ErrorMessage - If options in file are not valid according to
the specification.public static Options parse(java.lang.String[] args, java.lang.String[] specs) throws ErrorMessage
args - The command line split into arguments.specs - Option specification as in constructor.ErrorMessage - If options are not valid according to specs.