|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectml.options.Options
public class Options
The central class for option processing. Sets are identified by their name, but there is also an anonymous default set, which is very convenient if an application requieres only one set.
Nested Class Summary | |
---|---|
static class |
Options.Multiplicity
An enum encapsulating the possible multiplicities for options |
static class |
Options.Prefix
An enum encapsulating the possible prefixes identifying options (and separating them from command line data items) |
static class |
Options.Separator
An enum encapsulating the possible separators between value options and their actual values. |
Field Summary | |
---|---|
static String |
DEFAULT_SET
The name used internally for the default set |
Constructor Summary | |
---|---|
Options(String[] args)
Constructor. |
|
Options(String[] args,
int data)
Constructor. |
|
Options(String[] args,
int defMinData,
int defMaxData)
Constructor. |
|
Options(String[] args,
Options.Multiplicity defaultMultiplicity)
Constructor. |
|
Options(String[] args,
Options.Multiplicity defaultMultiplicity,
int data)
Constructor. |
|
Options(String[] args,
Options.Multiplicity defaultMultiplicity,
int defMinData,
int defMaxData)
Constructor. |
|
Options(String[] args,
Options.Prefix prefix)
Constructor. |
|
Options(String[] args,
Options.Prefix prefix,
int data)
Constructor. |
|
Options(String[] args,
Options.Prefix prefix,
int defMinData,
int defMaxData)
Constructor. |
|
Options(String[] args,
Options.Prefix prefix,
Options.Multiplicity defaultMultiplicity)
Constructor. |
|
Options(String[] args,
Options.Prefix prefix,
Options.Multiplicity defaultMultiplicity,
int data)
Constructor |
|
Options(String[] args,
Options.Prefix prefix,
Options.Multiplicity defaultMultiplicity,
int defMinData,
int defMaxData)
Constructor |
Method Summary | |
---|---|
void |
addOptionAllSets(String key)
Add the given non-value option to all known sets. |
void |
addOptionAllSets(String key,
boolean details,
Options.Separator separator)
Add the given value option to all known sets. |
void |
addOptionAllSets(String key,
boolean details,
Options.Separator separator,
Options.Multiplicity multiplicity)
Add the given value option to all known sets. |
void |
addOptionAllSets(String key,
Options.Multiplicity multiplicity)
Add the given non-value option to all known sets. |
void |
addOptionAllSets(String key,
Options.Separator separator)
Add the given value option to all known sets. |
void |
addOptionAllSets(String key,
Options.Separator separator,
Options.Multiplicity multiplicity)
Add the given value option to all known sets. |
OptionSet |
addSet(String setName)
Add an option set. |
OptionSet |
addSet(String setName,
int data)
Add an option set. |
OptionSet |
addSet(String setName,
int minData,
int maxData)
Add an option set. |
boolean |
check()
Run the checks for the default set. |
boolean |
check(boolean ignoreUnmatched,
boolean requireDataLast)
Run the checks for the default set. |
boolean |
check(String setName)
Run the checks for the given set. |
boolean |
check(String setName,
boolean ignoreUnmatched,
boolean requireDataLast)
Run the checks for the given set. |
String |
getCheckErrors()
The error messages collected during the last option check (invocation of any of the check() methods). |
OptionSet |
getMatchingSet()
Return the (first) matching set. |
OptionSet |
getMatchingSet(boolean ignoreUnmatched,
boolean requireDataLast)
Return the (first) matching set. |
OptionSet |
getSet()
This returns the (anonymous) default set |
OptionSet |
getSet(String setName)
Return an option set - or null , if no set with the given name exists |
String |
toString()
This is the overloaded Object.toString() method, and it is provided mainly for debugging
purposes. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final String DEFAULT_SET
Constructor Detail |
---|
public Options(String[] args, Options.Prefix prefix, Options.Multiplicity defaultMultiplicity, int defMinData, int defMaxData)
args
- The command line arguments to checkprefix
- The prefix to use for all command line options. It can only be set here for all options at
the same timedefaultMultiplicity
- The default multiplicity to use for all options (can be overridden when adding an option)defMinData
- The default minimum number of data items for all sets (can be overridden when adding a set)defMaxData
- The default maximum number of data items for all sets (can be overridden when adding a set)
IllegalArgumentException
- If either args
, prefix
, or defaultMultiplicity
is null
- or if the data range values don't make sensepublic Options(String[] args, Options.Prefix prefix, Options.Multiplicity defaultMultiplicity, int data)
args
- The command line arguments to checkprefix
- The prefix to use for all command line options. It can only be set here for all options at
the same timedefaultMultiplicity
- The default multiplicity to use for all options (can be overridden when adding an option)data
- The default minimum and maximum number of data items for all sets (can be overridden when adding a set)
IllegalArgumentException
- If either args
, prefix
, or defaultMultiplicity
is null
- or if the data range value doesn't make sensepublic Options(String[] args, Options.Prefix prefix, Options.Multiplicity defaultMultiplicity)
args
- The command line arguments to checkprefix
- The prefix to use for all command line options. It can only be set here for all options at
the same timedefaultMultiplicity
- The default multiplicity to use for all options (can be overridden when adding an option)
IllegalArgumentException
- If either args
, prefix
, or defaultMultiplicity
is null
public Options(String[] args, Options.Multiplicity defaultMultiplicity, int defMinData, int defMaxData)
Options.Prefix.DASH
.
args
- The command line arguments to checkdefaultMultiplicity
- The default multiplicity to use for all options (can be overridden when adding an option)defMinData
- The default minimum number of data items for all sets (can be overridden when adding a set)defMaxData
- The default maximum number of data items for all sets (can be overridden when adding a set)
IllegalArgumentException
- If either args
or defaultMultiplicity
is null
- or if the data range values don't make sensepublic Options(String[] args, Options.Multiplicity defaultMultiplicity, int data)
Options.Prefix.DASH
.
args
- The command line arguments to checkdefaultMultiplicity
- The default multiplicity to use for all options (can be overridden when adding an option)data
- The default minimum and maximum number of data items for all sets (can be overridden when adding a set)
IllegalArgumentException
- If either args
or defaultMultiplicity
is null
- or if the data range value doesn't make sensepublic Options(String[] args, Options.Multiplicity defaultMultiplicity)
Options.Prefix.DASH
, and the default number of data items is set to 0.
args
- The command line arguments to checkdefaultMultiplicity
- The default multiplicity to use for all options (can be overridden when adding an option)
IllegalArgumentException
- If either args
or defaultMultiplicity
is null
public Options(String[] args)
Options.Prefix.DASH
, the default number of data items is set to 0, and
the multiplicity is set to Options.Multiplicity.ONCE
.
args
- The command line arguments to check
IllegalArgumentException
- If args
is null
public Options(String[] args, int data)
Options.Prefix.DASH
, and
the multiplicity is set to Options.Multiplicity.ONCE
.
args
- The command line arguments to checkdata
- The default minimum and maximum number of data items for all sets (can be overridden when adding a set)
IllegalArgumentException
- If args
is null
- or if the data range value doesn't make sensepublic Options(String[] args, int defMinData, int defMaxData)
Options.Prefix.DASH
, and
the multiplicity is set to Options.Multiplicity.ONCE
.
args
- The command line arguments to checkdefMinData
- The default minimum number of data items for all sets (can be overridden when adding a set)defMaxData
- The default maximum number of data items for all sets (can be overridden when adding a set)
IllegalArgumentException
- If args
is null
- or if the data range values don't make sensepublic Options(String[] args, Options.Prefix prefix)
Options.Multiplicity.ONCE
.
args
- The command line arguments to checkprefix
- The prefix to use for all command line options. It can only be set here for all options at
the same time
IllegalArgumentException
- If either args
or prefix
is null
public Options(String[] args, Options.Prefix prefix, int data)
Options.Multiplicity.ONCE
.
args
- The command line arguments to checkprefix
- The prefix to use for all command line options. It can only be set here for all options atdata
- The default minimum and maximum number of data items for all sets (can be overridden when adding a set)
IllegalArgumentException
- If either args
or prefix
is null
- or if the data range value doesn't make sensepublic Options(String[] args, Options.Prefix prefix, int defMinData, int defMaxData)
Options.Multiplicity.ONCE
.
args
- The command line arguments to checkprefix
- The prefix to use for all command line options. It can only be set here for all options at
the same timedefMinData
- The default minimum number of data items for all sets (can be overridden when adding a set)defMaxData
- The default maximum number of data items for all sets (can be overridden when adding a set)
IllegalArgumentException
- If either args
or prefix
is null
- or if the data range values don't make senseMethod Detail |
---|
public OptionSet getMatchingSet()
check()
method returns true
) - or
null
, if no set matches.public OptionSet getMatchingSet(boolean ignoreUnmatched, boolean requireDataLast)
ignoreUnmatched
- A boolean to select whether unmatched options can be ignored in the checks or notrequireDataLast
- A boolean to indicate whether the data items have to be the last ones on the command line or not
check()
method returns true
) - or
null
, if no set matches.public OptionSet addSet(String setName, int minData, int maxData)
setName
- The name for the set. This must be a unique identifierminData
- The minimum number of data items for this setmaxData
- The maximum number of data items for this set
Optionset
instance created. This is useful to allow chaining of addOption()
calls right after this methodpublic OptionSet addSet(String setName, int data)
setName
- The name for the set. This must be a unique identifierdata
- The minimum and maximum number of data items for this set
Optionset
instance created. This is useful to allow chaining of addOption()
calls right after this methodpublic OptionSet addSet(String setName)
setName
- The name for the set. This must be a unique identifier
Optionset
instance created. This is useful to allow chaining of addOption()
calls right after this methodpublic OptionSet getSet(String setName)
null
, if no set with the given name exists
setName
- The name for the set to retrieve
null
, if no set with the given name exists)public OptionSet getSet()
public String getCheckErrors()
check()
methods). This
is useful to determine what was wrong with the command line arguments provided
public boolean check()
ignoreUnmatched
is set to false
, and
requireDataLast
is set to true
.
public boolean check(boolean ignoreUnmatched, boolean requireDataLast)
ignoreUnmatched
- A boolean to select whether unmatched options can be ignored in the checks or notrequireDataLast
- A boolean to indicate whether the data items have to be the last ones on the command line or not
public boolean check(String setName)
ignoreUnmatched
is set to false
, and
requireDataLast
is set to true
.
setName
- The name for the set to check
IllegalArgumentException
- If either setName
is null
, or the set is unknown.public boolean check(String setName, boolean ignoreUnmatched, boolean requireDataLast)
setName
- The name for the set to checkignoreUnmatched
- A boolean to select whether unmatched options can be ignored in the checks or notrequireDataLast
- A boolean to indicate whether the data items have to be the last ones on the command line or not
IllegalArgumentException
- If either setName
is null
, or the set is unknown.public void addOptionAllSets(String key)
OptionSet.addOption(String)
for details.
public void addOptionAllSets(String key, Options.Multiplicity multiplicity)
OptionSet.addOption(String, Options.Multiplicity)
for details.
public void addOptionAllSets(String key, Options.Separator separator)
OptionSet.addOption(String, Options.Separator)
for details.
public void addOptionAllSets(String key, Options.Separator separator, Options.Multiplicity multiplicity)
OptionSet.addOption(String, Options.Separator, Options.Multiplicity)
for details.
public void addOptionAllSets(String key, boolean details, Options.Separator separator)
OptionSet.addOption(String, boolean, Options.Separator)
for details.
public void addOptionAllSets(String key, boolean details, Options.Separator separator, Options.Multiplicity multiplicity)
OptionSet.addOption(String, boolean, Options.Separator, Options.Multiplicity)
for details.
public String toString()
Object.toString()
method, and it is provided mainly for debugging
purposes.
toString
in class Object
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |