ml.options
Class OptionSet

java.lang.Object
  extended by ml.options.OptionSet

public class OptionSet
extends Object

This class holds the information for a set of options. A set can hold any number of OptionData instances which are checked together to determine success or failure.

The approach to use this class looks like this:

  1. The user uses any of the Options.addSet() (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)
  2. The user adds all required option definitions to each set
  3. Using any of the Options.check() methods, each set can be checked whether the options that were specified on the command line satisfy its requirements
  4. If the check was successful for a given set, several data items are available from this class:


Method Summary
 OptionSet addOption(String key)
          Add a non-value option with the given key, and the default prefix and multiplicity
 OptionSet addOption(String key, boolean details, Options.Separator separator)
          Add a value option with the given key and separator, possibly details, and the default prefix and multiplicity
 OptionSet addOption(String key, boolean details, Options.Separator separator, Options.Multiplicity multiplicity)
          Add a value option with the given key, separator, and multiplicity, possibly details, and the default prefix
 OptionSet addOption(String key, Options.Multiplicity multiplicity)
          Add a non-value option with the given key and multiplicity, and the default prefix
 OptionSet addOption(String key, Options.Separator separator)
          Add a value option with the given key and separator, no details, and the default prefix and multiplicity
 OptionSet addOption(String key, Options.Separator separator, Options.Multiplicity multiplicity)
          Add a value option with the given key, separator, and multiplicity, no details, and the default prefix
 ArrayList<String> getData()
          Return the data items found (these are the items on the command line which do not start with the prefix, i.
 int getMaxData()
          Getter method for maxData property
 int getMinData()
          Getter method for minData property
 OptionData getOption(String key)
          Get the data for a specific option, identified by its key name (which is unique)
 ArrayList<OptionData> getOptionData()
          Get a list of all the options defined for this set
 String getSetName()
          Getter method for setName property
 ArrayList<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)
 boolean isSet(String key)
          Check whether a specific option is set, i.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getOptionData

public ArrayList<OptionData> getOptionData()
Get a list of all the options defined for this set

Returns:
A list of OptionData instances defined for this set

getOption

public OptionData getOption(String key)
Get the data for a specific option, identified by its key name (which is unique)

Parameters:
key - The key for the option

Returns:
The OptionData instance

Throws:
IllegalArgumentException - If the key is null or unknown in this set

isSet

public boolean isSet(String key)
Check whether a specific option is set, i. e. whether it was specified at least once on the command line.

Parameters:
key - The key for the option

Returns:
true or false, depending on the outcome of the check

Throws:
IllegalArgumentException - If the key is null or unknown in this set

getSetName

public String getSetName()
Getter method for setName property

Returns:
The value for the setName property

getMinData

public int getMinData()
Getter method for minData property

Returns:
The value for the minData property

getMaxData

public int getMaxData()
Getter method for maxData property

Returns:
The value for the maxData property

getData

public ArrayList<String> getData()
Return the data items found (these are the items on the command line which do not start with the prefix, i. e. non-option arguments)

Returns:
A list of strings with all data items found

getUnmatched

public ArrayList<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)

Returns:
A list of strings with all unmatched items found

addOption

public OptionSet addOption(String key)
Add a non-value option with the given key, and the default prefix and multiplicity

Parameters:
key - The key for the option

Returns:
The set instance itself (to support invocation chaining for addOption() methods)

Throws:
IllegalArgumentException - If the key is null or a key with this name has already been defined

addOption

public OptionSet addOption(String key,
                           Options.Multiplicity multiplicity)
Add a non-value option with the given key and multiplicity, and the default prefix

Parameters:
key - The key for the option
multiplicity - The multiplicity for the option

Returns:
The set instance itself (to support invocation chaining for addOption() methods)

Throws:
IllegalArgumentException - If the key is null or a key with this name has already been defined or if multiplicity is null

addOption

public OptionSet addOption(String key,
                           Options.Separator separator)
Add a value option with the given key and separator, no details, and the default prefix and multiplicity

Parameters:
key - The key for the option
separator - The separator for the option

Returns:
The set instance itself (to support invocation chaining for addOption() methods)

Throws:
IllegalArgumentException - If the key is null or a key with this name has already been defined or if separator is null

addOption

public OptionSet addOption(String key,
                           Options.Separator separator,
                           Options.Multiplicity multiplicity)
Add a value option with the given key, separator, and multiplicity, no details, and the default prefix

Parameters:
key - The key for the option
separator - The separator for the option
multiplicity - The multiplicity for the option

Returns:
The set instance itself (to support invocation chaining for addOption() methods)

Throws:
IllegalArgumentException - If the key is null or a key with this name has already been defined or if separator or multiplicity are null

addOption

public OptionSet addOption(String key,
                           boolean details,
                           Options.Separator separator)
Add a value option with the given key and separator, possibly details, and the default prefix and multiplicity

Parameters:
key - The key for the option
details - A boolean indicating whether details are expected for the option
separator - The separator for the option

Returns:
The set instance itself (to support invocation chaining for addOption() methods)

Throws:
IllegalArgumentException - If the key is null or a key with this name has already been defined or if separator is null

addOption

public OptionSet addOption(String key,
                           boolean details,
                           Options.Separator separator,
                           Options.Multiplicity multiplicity)
Add a value option with the given key, separator, and multiplicity, possibly details, and the default prefix

Parameters:
key - The key for the option
details - A boolean indicating whether details are expected for the option
separator - The separator for the option
multiplicity - The multiplicity for the option

Returns:
The set instance itself (to support invocation chaining for addOption() methods)

Throws:
IllegalArgumentException - If the key is null or a key with this name has already been defined or if separator or multiplicity are null