ml.options
public class OptionSet extends java.lang.Object implements Constrainable
OptionData
instances which are checked together to determine success or failure.
The approach to use this class looks like this:
Options.addSet()
methods
(e. g. Options.addSet(String)
) to create
any number of sets required (or just relies on the default set, if only one set is required)
Options.check()
methods, each set can be checked whether the options
that were specified on the command line satisfy its requirements
Modifier and Type | Field and Description |
---|---|
static int |
INF
A constant indicating an unlimited number of supported data items
|
Modifier and Type | Method and Description |
---|---|
boolean |
acceptsData()
Indicate whether this set accepts data (which means that
maxData is 1 or larger). |
void |
addConstraint(Constraint constraint)
Add a constraint for this option set
|
OptionData |
addOption(OptionData.Type type,
java.lang.String key)
Add the given option to the set.
|
OptionData |
addOption(OptionData.Type type,
java.lang.String key,
Options.Multiplicity multiplicity)
Add the given option to the set.
|
OptionData |
addOption(OptionData.Type type,
java.lang.String key,
java.lang.String altKey)
Add the given option to the set.
|
OptionData |
addOption(OptionData.Type type,
java.lang.String key,
java.lang.String altKey,
Options.Multiplicity multiplicity)
Add the given option to the set.
|
java.util.List<Constraint> |
getConstraints()
Get the constraints defined for this option set
|
java.util.List<java.lang.String> |
getData()
Return the data items found (these are the items on the command line
which do not start with the prefix, i.
|
java.lang.String |
getData(int index)
Return a specific data item.
|
int |
getDataCount()
Return the number of data items found (these are the items on the command line
which do not start with the prefix, i.
|
java.lang.String |
getDataText(int index)
Get the data text for a data item on the command line.
|
java.lang.String |
getHelpText(int index)
Get the help text for a data item on the command line.
|
int |
getMaxData()
Getter method for
maxData property |
int |
getMinData()
Getter method for
minData property |
java.lang.String |
getName()
Return the name of the set
|
OptionData |
getOption(java.lang.String key)
Get the data for a specific option, identified by its key name (which is unique)
|
java.util.List<OptionData> |
getOptionData()
Get a list of all the options defined for this set
|
java.util.List<java.lang.String> |
getUnmatched()
Return all unmatched items found (these are the items on the
command line which start with the prefix, but do not
match to one of the options)
|
java.lang.String |
getUnmatched(int index)
Return a specific unmatched item.
|
int |
getUnmatchedCount()
Return the number of unmatched items found (these are the items on the
command line which start with the prefix, but do not
match to one of the options)
|
boolean |
hasUnlimitedData()
Indicate whether this set has no upper limit for the number of allowed data items
|
boolean |
isDefault()
Indicate whether this set is the default set or not
|
boolean |
isSet(java.lang.String key)
Check whether a specific option is set, i.
|
void |
printResults()
A convenience method that prints all the results obtained for this option set to
System.out . |
OptionSet |
setDataText(int index,
java.lang.String text)
Set the data text for a data item on the command line.
|
OptionSet |
setHelpText(int index,
java.lang.String text)
Set the help text for a data item on the command line.
|
public static final int INF
public boolean hasUnlimitedData()
public boolean isDefault()
public void addConstraint(Constraint constraint)
addConstraint
in interface Constrainable
constraint
- The Constraint
to addpublic java.util.List<Constraint> getConstraints()
getConstraints
in interface Constrainable
null
if no constraints have been defined)public OptionSet setDataText(int index, java.lang.String text)
HelpPrinter
instances.
index
- The index for this data item on the command line. Must be within the allowed range of
0 ... maxData - 1
for this set. If this set supports an unlimited
number of data items, the allowed range is 0 ... minData
.text
- The text to use for this data item in the command line syntax
public OptionSet setHelpText(int index, java.lang.String text)
HelpPrinter
instances.
index
- The index for this data item on the command line. Must be within the allowed range of
0 ... maxData - 1
for this set. If this set supports an unlimited
number of data items, the allowed range is 0 ... minData
.text
- The help text to use to describe the purpose of the data item
public java.lang.String getDataText(int index)
index
- The index for this data item on the command line. Must be within the allowed range of
0 ... maxData - 1
for this set. If this set supports an unlimited
number of data items, the allowed range is 0 ... minData
.
public java.lang.String getHelpText(int index)
index
- The index for this data item on the command line. Must be within the allowed range of
0 ... maxData - 1
for this set. If this set supports an unlimited
number of data items, the allowed range is 0 ... minData
.
public java.util.List<OptionData> getOptionData()
OptionData
instances defined for this setpublic OptionData getOption(java.lang.String key)
key
- The key for the option
OptionData
instancepublic boolean isSet(java.lang.String key)
key
- The key for the option
true
or false
, depending on the outcome of the checkpublic java.lang.String getName()
public int getMinData()
minData
property
minData
propertypublic int getMaxData()
maxData
property
maxData
propertypublic boolean acceptsData()
maxData
is 1 or larger).
public java.util.List<java.lang.String> getData()
public int getDataCount()
public java.lang.String getData(int index)
index
- public java.util.List<java.lang.String> getUnmatched()
public int getUnmatchedCount()
public java.lang.String getUnmatched(int index)
index
- public OptionData addOption(OptionData.Type type, java.lang.String key)
type
- The type of the optionkey
- The name of the option
public OptionData addOption(OptionData.Type type, java.lang.String key, Options.Multiplicity multiplicity)
type
- The type of the optionkey
- The name of the optionmultiplicity
- The multiplicity of the option
public OptionData addOption(OptionData.Type type, java.lang.String key, java.lang.String altKey)
type
- The type of the optionkey
- The name of the optionaltKey
- The alternate name of the option
public OptionData addOption(OptionData.Type type, java.lang.String key, java.lang.String altKey, Options.Multiplicity multiplicity)
type
- The type of the optionkey
- The name of the optionaltKey
- The alternate name of the optionmultiplicity
- The multiplicity of the option
public void printResults()
System.out
. This is quite handy to quickly check whether a set definition
yields the expected results for a given set of command line arguments.