Top Description Methods
jdk.internal.joptsimple

public Interface OptionSpec<V>

Known Direct Implementers
jdk.internal.joptsimple.AbstractOptionSpec
Type Parameters
<V>
represents the type of the arguments this option accepts
Imports
java.util.List

Describes options that an option parser recognizes.

Instances of this interface are returned by the "fluent interface" methods to allow retrieval of option arguments in a type-safe manner. Here's an example:


    OptionParser parser = new OptionParser();
    OptionSpec<Integer> count =
        parser.accepts( "count" ).withRequiredArg().ofType( Integer.class );
    OptionSet options = parser.parse( "--count", "2" );
    assert options.has( count );
    int countValue = options.valueOf( count );
    assert countValue == count.value( options );
    List<Integer> countValues = options.valuesOf( count );
    assert countValues.equals( count.values( options ) );
Author
Paul Holser

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

whether this option is designated as a "help" option
isForHelp
()

Tells whether this option is designated as a "help" option.

public List<String>

Returns:

the string representations of this option
options
()

public V

Returns:

the argument of the this option; null if no argument is present, or that option was not detected
value
(OptionSet
the detected options to search in
detectedOptions
)

Gives the argument associated with the given option in the given set of detected options.

public List<V>

Returns:

the arguments associated with this option; an empty list if no such arguments are present, or if this option was not detected
values
(OptionSet
the detected options to search in
detectedOptions
)

Gives any arguments associated with the given option in the given set of detected options.

Method Detail

isForHelpback to summary
public boolean isForHelp()

Tells whether this option is designated as a "help" option. The presence of a "help" option on a command line means that missing "required" options will not cause parsing to fail.

Returns:boolean

whether this option is designated as a "help" option

optionsback to summary
public List<String> options()
Returns:List<String>

the string representations of this option

valueback to summary
public V value(OptionSet detectedOptions)

Gives the argument associated with the given option in the given set of detected options.

Specifying a default argument value for this option will cause this method to return that default value even if this option was not detected on the command line, or if this option can take an optional argument but did not have one on the command line.

Parameters
detectedOptions:OptionSet

the detected options to search in

Returns:V

the argument of the this option; null if no argument is present, or that option was not detected

Exceptions
OptionException:
if more than one argument was detected for the option
NullPointerException:
if detectedOptions is null
ClassCastException:
if the arguments of this option are not of the expected type
See Also
OptionSet#valueOf(OptionSpec)
valuesback to summary
public List<V> values(OptionSet detectedOptions)

Gives any arguments associated with the given option in the given set of detected options.

Specifying a default argument value for this option will cause this method to return that default value even if this option was not detected on the command line, or if this option can take an optional argument but did not have one on the command line.

Parameters
detectedOptions:OptionSet

the detected options to search in

Returns:List<V>

the arguments associated with this option; an empty list if no such arguments are present, or if this option was not detected

Exceptions
OptionException:
if there is a problem converting this option's arguments to the desired type; for example, if the type does not implement a correct conversion constructor or method
NullPointerException:
if detectedOptions is null
See Also
OptionSet#valuesOf(OptionSpec)