Class Options
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
An enum encapsulating the possible multiplicities for optionsstatic enum
An enum encapsulating the possible prefixes identifying options (and separating them from command line data items)static enum
An enum encapsulating the possible separators between value options and their actual values. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addOptionAllSets
(OptionData.Type type, String key) Add the given option to all known sets.void
addOptionAllSets
(OptionData.Type type, String key, String altKey) Add the given option to all known sets.void
addOptionAllSets
(OptionData.Type type, String key, String altKey, Options.Multiplicity multiplicity) Add the given option to all known sets.void
addOptionAllSets
(OptionData.Type type, String key, Options.Multiplicity multiplicity) Add the given option to all known sets.Add an option set.Add an option set.Add an option 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
Run the checks for the given set with default parameters.boolean
Run the checks for the given set.The error messages collected during the last option check (invocation of any of thecheck()
methods).Return the (first) matching set.getMatchingSet
(boolean ignoreUnmatched, boolean requireDataLast) Return the (first) matching set.getSet()
This returns the (anonymous) default setReturn an option set - ornull
, if no set with the given name existsvoid
Print a help description for this instance using aDefaultHelpPrinter
.void
printHelp
(HelpPrinter helpPrinter, String leadingText, boolean lineBreak, boolean printTexts) Print a help description for this instance using the providedHelpPrinter
.setDefault
(int defaultData) Define the defaults to use for the number of data items for a set.setDefault
(int defaultMinData, int defaultMaxData) Define the defaults to use for the number of data items for a set.setDefault
(Options.Multiplicity defaultMultiplicity) Define the default to use for the multiplicity for options.setDefault
(Options.Prefix defaultPrefix) Define the default to use for the option prefix.setDefault
(Options.Prefix defaultPrefix, Options.Prefix defaultAltPrefix) Define the defaults to use for the option prefixes.setDefault
(Options.Separator defaultValueSeparator) Define the default to use for the separator for value options.setDefault
(Options.Separator defaultValueSeparator, Options.Separator defaultDetailSeparator) Define the defaults to use for the separators for value and detail options.toString()
This is the overloadedObject.toString()
method.
-
Constructor Details
-
Options
Constructor- Parameters:
args
- The command line arguments to check
-
Options
This constructor uses the XML file provided by the reader to set up option sets and options.- Parameters:
args
- The command line arguments to checkreader
- The reader instance providing the XML file- Throws:
org.jdom.JDOMException
-
-
Method Details
-
setDefault
Define the default to use for the separator for value options. Note that this method can only be invoked before any option set has been created.- Parameters:
defaultValueSeparator
- The default separator to use for all value options- Returns:
- This instance to allow for invocation chaining
-
setDefault
public Options setDefault(Options.Separator defaultValueSeparator, Options.Separator defaultDetailSeparator) Define the defaults to use for the separators for value and detail options. Note that this method can only be invoked before any option set has been created.- Parameters:
defaultValueSeparator
- The default separator to use for all value optionsdefaultDetailSeparator
- The default separator to use for all detail options- Returns:
- This instance to allow for invocation chaining
-
setDefault
Define the default to use for the option prefix. Note that this method can only be invoked before any option set has been created.- Parameters:
defaultPrefix
- The prefix to use for all options- Returns:
- This instance to allow for invocation chaining
-
setDefault
Define the defaults to use for the option prefixes. Note that this method can only be invoked before any option set has been created.- Parameters:
defaultPrefix
- The prefix to use for all optionsdefaultAltPrefix
- The prefix to use for all alternate keys for options- Returns:
- This instance to allow for invocation chaining
-
setDefault
Define the default to use for the multiplicity for options. This applies only to option sets and options within these sets which are created after this call.- Parameters:
defaultMultiplicity
- The default multiplicity to use for all options- Returns:
- This instance to allow for invocation chaining
-
setDefault
Define the defaults to use for the number of data items for a set. This applies only to option sets which are created after this call.- Parameters:
defaultData
- The default minimum and maximum number of data items- Returns:
- This instance to allow for invocation chaining
-
setDefault
Define the defaults to use for the number of data items for a set. This applies only to option sets which are created after this call.- Parameters:
defaultMinData
- The default minimum number of data itemsdefaultMaxData
- The default maximum number of data items- Returns:
- This instance to allow for invocation chaining
-
getMatchingSet
Return the (first) matching set. This invocation does not ignore unmatched options and requires that data items are the last ones on the command line. It is equivalent to callinggetMatchingSet(false, true)
.- Returns:
- The first set which matches (i. e. the
check()
method returnstrue
) - ornull
, if no set matches.
-
getMatchingSet
Return the (first) matching set.- Parameters:
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- Returns:
- The first set which matches (i. e. the
check()
method returnstrue
) - ornull
, if no set matches.
-
addSet
Add an option set.- Parameters:
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 toOptionSet.INF
, this effectively corresponds to an unlimited number)- Returns:
- The new
OptionSet
instance created. This is useful to allow chaining ofaddOption()
calls right after this method
-
addSet
Add an option set.- Parameters:
name
- The name for the set. This must be a unique identifierdata
- The minimum and maximum number of data items for this set- Returns:
- The new
OptionSet
instance created. This is useful to allow chaining ofaddOption()
calls right after this method
-
addSet
Add an option set. The defaults for the number of data items are used.- Parameters:
name
- The name for the set. This must be a unique identifier- Returns:
- The new
OptionSet
instance created. This is useful to allow chaining ofaddOption()
calls right after this method
-
addSet
Add an option set by cloning an existing set. Note that is designed for setup purposes only, i. e. no check result data is copied either for the set or any options. This method can be very handy if an application requires two (or more) sets which have a lot of options in common and differ only in a few of them. In this case, one would first create a set with the common options, then clone any number of additionally required sets, and add the non-common options to each of these sets.Note that it is not possible to change the number of data items required for the new set.
- Parameters:
name
- The name for the new set. This must be a unique identifierset
- The set to clone the new set from- Returns:
- The new
OptionSet
instance created. This is useful to allow chaining ofaddOption()
calls right after this method
-
getSet
Return an option set - ornull
, if no set with the given name exists- Parameters:
name
- The name for the set to retrieve- Returns:
- The set to retrieve (or
null
, if no set with the given name exists)
-
printHelp
Print a help description for this instance using aDefaultHelpPrinter
. 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. IfprintTexts
istrue
, 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
andOptionData
classes.- Parameters:
leadingText
- The text to precede the command line for each option set (seeHelpPrinter.getCommandLine(OptionSet, String, boolean)
)lineBreak
- A boolean indicating whether the command lines for the option sets should be printed with line breaks or not (seeHelpPrinter.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 lines
-
printHelp
public void printHelp(HelpPrinter helpPrinter, String leadingText, boolean lineBreak, boolean printTexts) Print a help description for this instance using the providedHelpPrinter
. 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. IfprintTexts
istrue
, 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
andOptionData
classes.- Parameters:
helpPrinter
- TheHelpPrinter
to use to format the outputleadingText
- The text to precede the command line for each option set (seeHelpPrinter.getCommandLine(OptionSet, String, boolean)
)lineBreak
- A boolean indicating whether the command lines for the option sets should be printed with line breaks or not (seeHelpPrinter.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 lines
-
getSet
This returns the (anonymous) default set- Returns:
- The default set
-
toString
This is the overloadedObject.toString()
method. -
getCheckErrors
The error messages collected during the last option check (invocation of any of thecheck()
methods). This is useful to determine what was wrong with the command line arguments provided- Returns:
- A string with all collected error messages
-
check
public boolean check()Run the checks for the default set with default parameters. This is equivalent to callingcheck(false, true)
. If the default set has not yet been used at all, it is created here with the default settings.- Returns:
- A boolean indicating whether all checks were successful or not
-
check
public boolean check(boolean ignoreUnmatched, boolean requireDataLast) Run the checks for the default set. If the default set has not yet been used at all, it is created here with the default settings.- Parameters:
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- Returns:
- A boolean indicating whether all checks were successful or not
-
check
Run the checks for the given set with default parameters. This is equivalent to callingcheck(name, false, true)
.- Parameters:
name
- The name for the set to check- Returns:
- A boolean indicating whether all checks were successful or not
-
check
Run the checks for the given set.- Parameters:
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- Returns:
- A boolean indicating whether all checks were successful or not
-
addOptionAllSets
Add the given option to all known sets.- Parameters:
type
- The type of the optionkey
- The name of the option
-
addOptionAllSets
Add the given option to all known sets.- Parameters:
type
- The type of the optionkey
- The name of the optionmultiplicity
- The multiplicity of the option
-
addOptionAllSets
Add the given option to all known sets.- Parameters:
type
- The type of the optionkey
- The name of the optionaltKey
- The alternate name of the option
-
addOptionAllSets
public void addOptionAllSets(OptionData.Type type, String key, String altKey, Options.Multiplicity multiplicity) Add the given option to all known sets.- Parameters:
type
- The type of the optionkey
- The name of the optionaltKey
- The alternate name of the optionmultiplicity
- The multiplicity of the option
-