ml.options
public class Options extends java.lang.Object
The default values used in this class are:
Default Values | |||
ID | Parameter | Default | Individual Setting |
1 | Prefix | Prefix.SLASH (Windows) Prefix.DASH (all others)
| No |
2 | Alternate Prefix | Prefix.DOUBLEDASH
| No |
3 | Separator for value options | Separator.BLANK
| No |
4 | Separator for detail options | Separator.EQUALS
| No |
5 | Min. Data | 0
| Option set level |
6 | Max. Data | 0
| Option set level |
7 | Multiplicity | Multiplicity.ZERO_OR_ONCE
| Option level |
All of these values can be changed using one of the setDefault()
methods. However, for
1 - 4 this can only be done before any actual set or option has been created (otherwise an
UnsupportedOperationException
is thrown). 5 - 7 can be called
anytime, but they affect only sets and options which are created afterwards.
Modifier and Type | Class and Description |
---|---|
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.
|
Constructor and Description |
---|
Options(java.lang.String[] args)
Constructor
|
Options(java.lang.String[] args,
java.io.Reader reader)
This constructor uses the XML file provided by the reader to set up option sets and options.
|
Modifier and Type | Method and Description |
---|---|
void |
addOptionAllSets(OptionData.Type type,
java.lang.String key)
Add the given option to all known sets.
|
void |
addOptionAllSets(OptionData.Type type,
java.lang.String key,
Options.Multiplicity multiplicity)
Add the given option to all known sets.
|
void |
addOptionAllSets(OptionData.Type type,
java.lang.String key,
java.lang.String altKey)
Add the given option to all known sets.
|
void |
addOptionAllSets(OptionData.Type type,
java.lang.String key,
java.lang.String altKey,
Options.Multiplicity multiplicity)
Add the given option to all known sets.
|
OptionSet |
addSet(java.lang.String name)
Add an option set.
|
OptionSet |
addSet(java.lang.String name,
int data)
Add an option set.
|
OptionSet |
addSet(java.lang.String name,
int minData,
int maxData)
Add an option set.
|
OptionSet |
addSet(java.lang.String name,
OptionSet set)
Add an option set by cloning an existing set.
|
boolean |
check()
Run the checks for the default set with default parameters.
|
boolean |
check(boolean ignoreUnmatched,
boolean requireDataLast)
Run the checks for the default set.
|
boolean |
check(java.lang.String name)
Run the checks for the given set with default parameters.
|
boolean |
check(java.lang.String name,
boolean ignoreUnmatched,
boolean requireDataLast)
Run the checks for the given set.
|
java.lang.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(java.lang.String name)
Return an option set - or
null , if no set with the given name exists |
void |
printHelp(HelpPrinter helpPrinter,
java.lang.String leadingText,
boolean lineBreak,
boolean printTexts)
Print a help description for this instance using the provided
HelpPrinter . |
void |
printHelp(java.lang.String leadingText,
boolean lineBreak,
boolean printTexts)
Print a help description for this instance using a
DefaultHelpPrinter . |
Options |
setDefault(int defaultData)
Define the defaults to use for the number of data items for a set.
|
Options |
setDefault(int defaultMinData,
int defaultMaxData)
Define the defaults to use for the number of data items for a set.
|
Options |
setDefault(Options.Multiplicity defaultMultiplicity)
Define the default to use for the multiplicity for options.
|
Options |
setDefault(Options.Prefix defaultPrefix)
Define the default to use for the option prefix.
|
Options |
setDefault(Options.Prefix defaultPrefix,
Options.Prefix defaultAltPrefix)
Define the defaults to use for the option prefixes.
|
Options |
setDefault(Options.Separator defaultValueSeparator)
Define the default to use for the separator for value options.
|
Options |
setDefault(Options.Separator defaultValueSeparator,
Options.Separator defaultDetailSeparator)
Define the defaults to use for the separators for value and detail options.
|
java.lang.String |
toString()
This is the overloaded
Object.toString() method. |
public Options(java.lang.String[] args)
args
- The command line arguments to checkpublic Options(java.lang.String[] args, java.io.Reader reader) throws org.jdom.JDOMException
args
- The command line arguments to checkreader
- The reader instance providing the XML fileorg.jdom.JDOMException
public Options setDefault(Options.Separator defaultValueSeparator)
defaultValueSeparator
- The default separator to use for all value options
public Options setDefault(Options.Separator defaultValueSeparator, Options.Separator defaultDetailSeparator)
defaultValueSeparator
- The default separator to use for all value optionsdefaultDetailSeparator
- The default separator to use for all detail options
public Options setDefault(Options.Prefix defaultPrefix)
defaultPrefix
- The prefix to use for all options
public Options setDefault(Options.Prefix defaultPrefix, Options.Prefix defaultAltPrefix)
defaultPrefix
- The prefix to use for all optionsdefaultAltPrefix
- The prefix to use for all alternate keys for options
public Options setDefault(Options.Multiplicity defaultMultiplicity)
defaultMultiplicity
- The default multiplicity to use for all options
public Options setDefault(int defaultData)
defaultData
- The default minimum and maximum number of data items
public Options setDefault(int defaultMinData, int defaultMaxData)
defaultMinData
- The default minimum number of data itemsdefaultMaxData
- The default maximum number of data items
public OptionSet getMatchingSet()
getMatchingSet(false, true)
.
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(java.lang.String name, int minData, int maxData)
name
- 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 (if set to OptionSet.INF
, this
effectively corresponds to an unlimited number)
OptionSet
instance created. This is useful to allow
chaining of addOption()
calls right after this methodpublic OptionSet addSet(java.lang.String name, int data)
name
- 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(java.lang.String name)
name
- 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 addSet(java.lang.String name, OptionSet set)
Note that it is not possible to change the number of data items required for the new set.
name
- The name for the new set. This must be a unique identifierset
- The set to clone the new set from
OptionSet
instance created. This is useful to allow chaining
of addOption()
calls right after this methodpublic OptionSet getSet(java.lang.String name)
null
, if no set with the given name exists
name
- The name for the set to retrieve
null
, if no set with the given name exists)public void printHelp(java.lang.String leadingText, boolean lineBreak, boolean printTexts)
DefaultHelpPrinter
. This method
provides a basic service in the sense that it loops over all known option sets
and prints the command line for each set. If printTexts
is true
, also
descriptive texts are printed for all options and the data arguments.
Note that default values are used for all the components of the helper text, which can be
overridden by various methods available in the OptionSet
and OptionData
classes.
leadingText
- The text to precede the command line for each
option set (see HelpPrinter.getCommandLine(OptionSet, String, boolean)
)lineBreak
- A boolean indicating whether the command lines for the option sets should
be printed with line breaks or not
(see HelpPrinter.getCommandLine(OptionSet, String, boolean)
)printTexts
- A boolean indicating whether the full help information should be printer (command lines
and description texts) or just the command linespublic void printHelp(HelpPrinter helpPrinter, java.lang.String leadingText, boolean lineBreak, boolean printTexts)
HelpPrinter
. This method
provides a basic service in the sense that it loops over all known option sets
and prints the command line for each set. If printTexts
is true
, also
descriptive texts are printed for all options and the data arguments.
Note that default values are used for all the components of the helper text, which can be
overridden by various methods available in the OptionSet
and OptionData
classes.
helpPrinter
- The HelpPrinter
to use to format the outputleadingText
- The text to precede the command line for each
option set (see HelpPrinter.getCommandLine(OptionSet, String, boolean)
)lineBreak
- A boolean indicating whether the command lines for the option sets should
be printed with line breaks or not
(see HelpPrinter.getCommandLine(OptionSet, String, boolean)
)printTexts
- A boolean indicating whether the full help information should be printer (command lines
and description texts) or just the command linespublic OptionSet getSet()
public java.lang.String toString()
Object.toString()
method.
toString
in class java.lang.Object
public java.lang.String getCheckErrors()
check()
methods). This
is useful to determine what was wrong with the command
line arguments provided
public boolean check()
check(false, true)
. If the default set has not yet been
used at all, it is created here with the default settings.
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(java.lang.String name)
check(name, false, true)
.
name
- The name for the set to check
public boolean check(java.lang.String name, boolean ignoreUnmatched, boolean requireDataLast)
name
- 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
public void addOptionAllSets(OptionData.Type type, java.lang.String key)
type
- The type of the optionkey
- The name of the optionpublic void addOptionAllSets(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 optionpublic void addOptionAllSets(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 optionpublic void addOptionAllSets(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