package com.minres.scviewer.e4.application.options;
/**
* 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: *
*
Options.addSet()
(e. g. {@link 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
*
* @return A list of {@link OptionData} instances defined for this set
*/
public java.util.ArrayList
* @param key The key for the option
*
* @return The {@link OptionData} instance
*
* @throws IllegalArgumentException If the
* @param key The key for the option
*
* @return
* @throws IllegalArgumentException If the
* @return The value for the
* @return The value for the
* @return The value for the
* @return A list of strings with all data items found
*/
public java.util.ArrayList
* @return A list of strings with all unmatched items found
*/
public java.util.ArrayList
* @param key The key for the option
*
* @return The set instance itself (to support invocation chaining for
* @throws IllegalArgumentException If the
* @param key The key for the option
* @param multiplicity The multiplicity for the option
*
* @return The set instance itself (to support invocation chaining for
* @throws IllegalArgumentException If the
* @param key The key for the option
* @param separator The separator for the option
*
* @return The set instance itself (to support invocation chaining for
* @throws IllegalArgumentException If the
* @param key The key for the option
* @param separator The separator for the option
* @param multiplicity The multiplicity for the option
*
* @return The set instance itself (to support invocation chaining for
* @throws IllegalArgumentException If the
* @param key The key for the option
* @param details A boolean indicating whether details are expected for the option
* @param separator The separator for the option
*
* @return The set instance itself (to support invocation chaining for
* @throws IllegalArgumentException If the
* @param key The key for the option
* @param details A boolean indicating whether details are expected for the option
* @param separator The separator for the option
* @param multiplicity The multiplicity for the option
*
* @return The set instance itself (to support invocation chaining for
* @throws IllegalArgumentException If the key
is null
or unknown in this set
*/
public OptionData getOption(String key) {
if (key == null) throw new IllegalArgumentException(CLASS + ": key may not be null");
if (!keys.containsKey(key)) throw new IllegalArgumentException(CLASS + ": unknown key: " + key);
return keys.get(key);
}
/**
* Check whether a specific option is set, i. e. whether it was specified at least once on the command line.
* true
or false
, depending on the outcome of the check
* key
is null
or unknown in this set
*/
public boolean isSet(String key) {
if (key == null) throw new IllegalArgumentException(CLASS + ": key may not be null");
if (!keys.containsKey(key)) throw new IllegalArgumentException(CLASS + ": unknown key: " + key);
return keys.get(key).getResultCount() > 0 ? true : false;
}
/**
* Getter method for setName
property
* setName
property
*/
public String getSetName() {
return setName;
}
/**
* Getter method for minData
property
* minData
property
*/
public int getMinData() {
return minData;
}
/**
* Getter method for maxData
property
* maxData
property
*/
public int getMaxData() {
return maxData;
}
/**
* 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)
* addOption()
methods)
* key
is null
or a key with this name has already been defined
*/
public OptionSet addOption(String key) {
return addOption(key, defaultMultiplicity);
}
/**
* Add a non-value option with the given key and multiplicity, and the default prefix
* addOption()
methods)
* key
is null
or a key with this name has already been defined
* or if multiplicity
is null
*/
public OptionSet addOption(String key, Options.Multiplicity multiplicity) {
return addOption(key, false, Options.Separator.NONE, false, multiplicity);
}
/**
* Add a value option with the given key and separator, no details, and the default prefix and multiplicity
* addOption()
methods)
* key
is null
or a key with this name has already been defined
* or if separator
is null
*/
public OptionSet addOption(String key, Options.Separator separator) {
return addOption(key, false, separator, true, defaultMultiplicity);
}
/**
* Add a value option with the given key, separator, and multiplicity, no details, and the default prefix
* addOption()
methods)
* key
is null
or a key with this name has already been defined
* or if separator
or multiplicity
are null
*/
public OptionSet addOption(String key, Options.Separator separator, Options.Multiplicity multiplicity) {
return addOption(key, false, separator, true, multiplicity);
}
/**
*
* Add a value option with the given key and separator, possibly details, and the default prefix and multiplicity
* addOption()
methods)
* key
is null
or a key with this name has already been defined
* or if separator
is null
*/
public OptionSet addOption(String key, boolean details, Options.Separator separator) {
return addOption(key, details, separator, true, defaultMultiplicity);
}
/**
* Add a value option with the given key, separator, and multiplicity, possibly details, and the default prefix
* addOption()
methods)
* key
is null
or a key with this name has already been defined
* or if separator
or multiplicity
are null
*/
public OptionSet addOption(String key, boolean details, Options.Separator separator, Options.Multiplicity multiplicity) {
return addOption(key, details, separator, true, multiplicity);
}
/**
* The master method to add an option. Since there are combinations which are not
* acceptable (like a NONE separator and a true value), this method is not public.
* Internally, we only supply acceptable combinations.
*/
OptionSet addOption(String key,
boolean details,
Options.Separator separator,
boolean value,
Options.Multiplicity multiplicity) {
if (key == null) throw new IllegalArgumentException(CLASS + ": key may not be null");
if (multiplicity == null) throw new IllegalArgumentException(CLASS + ": multiplicity may not be null");
if (separator == null) throw new IllegalArgumentException(CLASS + ": separator may not be null");
if (keys.containsKey(key)) throw new IllegalArgumentException(CLASS + ": the key "
+ key + " has already been defined for this OptionSet");
OptionData od = new OptionData(prefix, key, details, separator, value, multiplicity);
options.add(od);
keys.put(key, od);
return this;
}
}