public class OptionSet extends Object
Modifier and Type | Method and Description |
---|---|
Map<OptionSpec<?>,List<?>> |
asMap()
Gives all declared options as a map of string to OptionSpec.
|
boolean |
equals(Object that) |
boolean |
has(OptionSpec<?> option)
Tells whether the given option was detected.
|
boolean |
has(String option)
Tells whether the given option was detected.
|
boolean |
hasArgument(OptionSpec<?> option)
Tells whether there are any arguments associated with the given option.
|
boolean |
hasArgument(String option)
Tells whether there are any arguments associated with the given option.
|
int |
hashCode() |
boolean |
hasOptions()
Tells whether any options were detected.
|
List<?> |
nonOptionArguments() |
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.
|
<V> V |
valueOf(OptionSpec<V> option)
Gives the argument associated with the given option.
|
Object |
valueOf(String option)
Gives the argument associated with the given option.
|
<V> Optional<V> |
valueOfOptional(OptionSpec<V> option)
Gives the argument associated with the given option as an
Optional . |
Optional<Object> |
valueOfOptional(String option)
Gives the argument associated with the given option, as an
Optional . |
<V> List<V> |
valuesOf(OptionSpec<V> option)
Gives any arguments associated with the given option.
|
List<?> |
valuesOf(String option)
Gives any arguments associated with the given option.
|
public boolean hasOptions()
true
if any options were detectedpublic boolean has(String option)
option
- the option to search fortrue
if the option was detectedhas(OptionSpec)
public boolean has(OptionSpec<?> option)
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 true
if the option was not detected on the command
line.
option
- the option to search fortrue
if the option was detectedhas(String)
public boolean hasArgument(String option)
option
- the option to search fortrue
if the option was detected and at least one argument was detected for the optionhasArgument(OptionSpec)
public boolean hasArgument(OptionSpec<?> 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 true
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.
option
- the option to search fortrue
if the option was detected and at least one argument was detected for the optionNullPointerException
- if option
is null
hasArgument(String)
public Object valueOf(String option)
String
.
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.
option
- the option to search fornull
if no argument is present, or that option was not
detectedNullPointerException
- if option
is null
OptionException
- if more than one argument was detected for the optionpublic Optional<Object> valueOfOptional(String option)
Optional
.
If the option was given an argument type, the argument will take on that type;
otherwise, it will be a String
.
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.
option
- the option to search forOptional
NullPointerException
- if option
is null
OptionException
- if more than one argument was detected for the optionpublic <V> V valueOf(OptionSpec<V> option)
This method recognizes only instances of options returned from the fluent interface methods.
V
- represents the type of the arguments the given option acceptsoption
- the option to search fornull
if no argument is present, or that option was not
detectedOptionException
- if more than one argument was detected for the optionNullPointerException
- if option
is null
ClassCastException
- if the arguments of this option are not of the expected typepublic <V> Optional<V> valueOfOptional(OptionSpec<V> option)
Optional
.
This method recognizes only instances of options returned from the fluent interface methods.
V
- represents the type of the arguments the given option acceptsoption
- the option to search forOptional
OptionException
- if more than one argument was detected for the optionNullPointerException
- if option
is null
ClassCastException
- if the arguments of this option are not of the expected typepublic List<?> valuesOf(String option)
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 String
s.
option
- the option to search forNullPointerException
- if option
is null
public <V> List<V> valuesOf(OptionSpec<V> option)
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 String
s.
This method recognizes only instances of options returned from the fluent interface methods.
V
- represents the type of the arguments the given option acceptsoption
- the option to search forNullPointerException
- if option
is null
OptionException
- 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 methodpublic List<OptionSpec<?>> specs()
public Map<OptionSpec<?>,List<?>> asMap()
public List<?> nonOptionArguments()
© Copyright 2004-2016 Paul R. Holser, Jr. All rights reserved. Licensed under The MIT License.