|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjoptsimple.ArgumentAcceptingOptionSpec<V>
V
- represents the type of the arguments this option acceptspublic abstract class ArgumentAcceptingOptionSpec<V>
Specification of an option that accepts an argument.
Instances are returned from OptionSpecBuilder
methods to allow the formation
of parser directives as sentences in a "fluent interface" language. For example:
OptionParser parser = new OptionParser();
parser.accepts( "c" ).withRequiredArg().ofType( Integer.class );
If no methods are invoked on an instance of this class, then that instance's option
will treat its argument as a String
.
Method Summary | ||
---|---|---|
protected void |
addArguments(OptionSet detectedOptions,
String detectedArgument)
|
|
protected boolean |
canConvertArgument(String argument)
|
|
protected V |
convert(String argument)
|
|
ArgumentAcceptingOptionSpec<V> |
defaultsTo(V value,
V... values)
Specifies a set of default values for the argument of the option that this spec represents. |
|
ArgumentAcceptingOptionSpec<V> |
describedAs(String description)
Specifies a description for the argument of the option that this spec represents. |
|
protected abstract void |
detectOptionArgument(OptionParser parser,
joptsimple.ArgumentList arguments,
OptionSet detectedOptions)
|
|
boolean |
equals(Object that)
|
|
int |
hashCode()
|
|
protected boolean |
isArgumentOfNumberType()
|
|
|
ofType(Class<T> argumentType)
Specifies a type to which arguments of this spec's option are to be converted. |
|
Collection<String> |
options()
|
|
String |
toString()
|
|
V |
value(OptionSet detectedOptions)
Gives the argument associated with the given option in the given set of detected options. |
|
List<V> |
values(OptionSet detectedOptions)
Gives any arguments associated with the given option in the given set of detected options. |
|
|
withValuesConvertedBy(ValueConverter<T> aConverter)
Specifies a converter to use to translate arguments of this spec's option into Java objects. |
|
ArgumentAcceptingOptionSpec<V> |
withValuesSeparatedBy(char separator)
Specifies a value separator for the argument of the option that this spec represents. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Method Detail |
---|
public final <T> ArgumentAcceptingOptionSpec<T> ofType(Class<T> argumentType)
Specifies a type to which arguments of this spec's option are to be converted.
JOpt Simple accepts types that have either:
valueOf
which accepts a single
argument of type String
and whose return type is the same as the class
on which the method is declared. The java.lang
primitive wrapper
classes have such methods.String
.This class converts arguments using those methods in that order; that is,
valueOf
would be invoked before a one-String
-arg constructor
would.
Invoking this method will trump any previous calls to this method or to
withValuesConvertedBy(ValueConverter)
.
T
- represents the runtime class of the desired option argument typeargumentType
- desired type of arguments to this spec's option
NullPointerException
- if the type is null
IllegalArgumentException
- if the type does not have the standard conversion
methodspublic final <T> ArgumentAcceptingOptionSpec<T> withValuesConvertedBy(ValueConverter<T> aConverter)
Specifies a converter to use to translate arguments of this spec's option into
Java objects. This is useful when converting to types that do not have the
requisite factory method or constructor for ofType(Class)
.
Invoking this method will trump any previous calls to this method or to
ofType(Class)
.
T
- represents the runtime class of the desired option argument typeaConverter
- the converter to use
NullPointerException
- if the converter is null
public final ArgumentAcceptingOptionSpec<V> describedAs(String description)
Specifies a description for the argument of the option that this spec represents. This description is used when generating help information about the parser.
description
- describes the nature of the argument of this spec's
option
public final ArgumentAcceptingOptionSpec<V> withValuesSeparatedBy(char separator)
Specifies a value separator for the argument of the option that this spec represents. This allows a single option argument to represent multiple values for the option. For example:
parser.accepts( "z" ).withRequiredArg()
.withValuesSeparatedBy( ',' );
OptionSet options = parser.parse( new String[] { "-z", "foo,bar,baz", "-z",
"fizz", "-z", "buzz" } );
Then options.valuesOf( "z" )
would yield the list [foo, bar,
baz, fizz, buzz]
.
You cannot use Unicode U+0000 as the separator.
separator
- a character separator
IllegalArgumentException
- if the separator is Unicode U+0000public ArgumentAcceptingOptionSpec<V> defaultsTo(V value, V... values)
Specifies a set of default values for the argument of the option that this spec represents.
value
- the first in the set of default argument values for this spec's optionvalues
- the (optional) remainder of the set of default argument values for this spec's option
NullPointerException
- if value
, values
, or any elements of values
are
null
protected void addArguments(OptionSet detectedOptions, String detectedArgument)
protected abstract void detectOptionArgument(OptionParser parser, joptsimple.ArgumentList arguments, OptionSet detectedOptions)
protected final V convert(String argument)
protected boolean canConvertArgument(String argument)
protected boolean isArgumentOfNumberType()
public boolean equals(Object that)
public int hashCode()
public final Collection<String> options()
options
in interface OptionSpec<V>
public final List<V> values(OptionSet detectedOptions)
OptionSpec
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.
values
in interface OptionSpec<V>
detectedOptions
- the detected options to search in
OptionSet.valuesOf(OptionSpec)
public final V value(OptionSet detectedOptions)
OptionSpec
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.
value
in interface OptionSpec<V>
detectedOptions
- the detected options to search in
null
if no argument is present,
or that option was not detectedOptionSet.valueOf(OptionSpec)
public String toString()
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |