Class OptionSet
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Map<String, AbstractOptionSpec<?>> private final List<OptionSpec<?>> private final Map<AbstractOptionSpec<?>, List<String>> private final Map<String, AbstractOptionSpec<?>> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) voidadd(AbstractOptionSpec<?> spec) (package private) voidaddWithArgument(AbstractOptionSpec<?> spec, String argument) Map<OptionSpec<?>, List<?>> asMap()Gives all declared options as a map of string to OptionSpec.private <V> List<V> defaultValueFor(OptionSpec<V> option) defaultValues(Map<String, AbstractOptionSpec<?>> recognizedSpecs) private <V> List<V> defaultValuesFor(String option) booleanbooleanTells whether the given option was detected.booleanhas(OptionSpec<?> option) Tells whether the given option was detected.booleanhasArgument(String option) Tells whether there are any arguments associated with the given option.booleanhasArgument(OptionSpec<?> option) Tells whether there are any arguments associated with the given option.inthashCode()booleanTells whether any options were detected.List<?> List<OptionSpec<?>> specs()Gives the set of options that were detected, in the form of OptionSpecs, in the order in which the options were found on the command line.Gives the argument associated with the given option.<V> VvalueOf(OptionSpec<V> option) Gives the argument associated with the given option.List<?> Gives any arguments associated with the given option.<V> List<V> valuesOf(OptionSpec<V> option) Gives any arguments associated with the given option.
-
Field Details
-
detectedSpecs
-
detectedOptions
-
optionsToArguments
-
recognizedSpecs
-
defaultValues
-
-
Constructor Details
-
OptionSet
OptionSet(Map<String, AbstractOptionSpec<?>> recognizedSpecs)
-
-
Method Details
-
hasOptions
public boolean hasOptions()Tells whether any options were detected.- Returns:
trueif any options were detected
-
has
Tells whether the given option was detected.- Parameters:
option- the option to search for- Returns:
trueif the option was detected- See Also:
-
has
Tells whether the given option was detected.This method recognizes only instances of options returned from the fluent interface methods.
Specifying a ArgumentAcceptingOptionSpec.defaultsTo(Object, Object[]) default argument value} for an option does not cause this method to return
trueif the option was not detected on the command line.- Parameters:
option- the option to search for- Returns:
trueif the option was detected- See Also:
-
hasArgument
Tells whether there are any arguments associated with the given option.- Parameters:
option- the option to search for- Returns:
trueif the option was detected and at least one argument was detected for the option- See Also:
-
hasArgument
Tells whether there are any arguments associated with the given option.This method recognizes only instances of options returned from the fluent interface methods.
Specifying a default argument value for an option does not cause this method to return
trueif the option was not detected on the command line, or if the option can take an optional argument but did not have one on the command line.- Parameters:
option- the option to search for- Returns:
trueif the option was detected and at least one argument was detected for the option- Throws:
NullPointerException- ifoptionisnull- See Also:
-
valueOf
Gives the argument associated with the given option. If the option was given an argument type, the argument will take on that type; otherwise, it will be aString.Specifying a default argument value for an option will cause this method to return that default value even if the option was not detected on the command line, or if the option can take an optional argument but did not have one on the command line.
- Parameters:
option- the option to search for- Returns:
- the argument of the given option;
nullif no argument is present, or that option was not detected - Throws:
NullPointerException- ifoptionisnullOptionException- if more than one argument was detected for the option
-
valueOf
Gives the argument associated with the given option.This method recognizes only instances of options returned from the fluent interface methods.
- Type Parameters:
V- represents the type of the arguments the given option accepts- Parameters:
option- the option to search for- Returns:
- the argument of the given option;
nullif no argument is present, or that option was not detected - Throws:
OptionException- if more than one argument was detected for the optionNullPointerException- ifoptionisnullClassCastException- if the arguments of this option are not of the expected type
-
valuesOf
Gives any arguments associated with the given option. If the option was given an argument type, the arguments will take on that type; otherwise, they will be
Strings.- Parameters:
option- the option to search for- Returns:
- the arguments associated with the option, as a list of objects of the type given to the arguments; an empty list if no such arguments are present, or if the option was not detected
- Throws:
NullPointerException- ifoptionisnull
-
valuesOf
Gives any arguments associated with the given option. If the option was given an argument type, the arguments will take on that type; otherwise, they will be
Strings.This method recognizes only instances of options returned from the fluent interface methods.
- Type Parameters:
V- represents the type of the arguments the given option accepts- Parameters:
option- the option to search for- Returns:
- the arguments associated with the option; an empty list if no such arguments are present, or if the option was not detected
- Throws:
NullPointerException- ifoptionisnullOptionException- if there is a problem converting the option's arguments to the desired type; for example, if the type does not implement a correct conversion constructor or method
-
specs
Gives the set of options that were detected, in the form of OptionSpecs, in the order in which the options were found on the command line.- Returns:
- the set of detected command line options
-
asMap
Gives all declared options as a map of string to OptionSpec.- Returns:
- the declared options as a map
-
nonOptionArguments
- Returns:
- the detected non-option arguments
-
add
-
addWithArgument
-
equals
-
hashCode
public int hashCode() -
defaultValuesFor
-
defaultValueFor
-
defaultValues
-