APIdia Launch Partner
Top Description Fields Constructors Methods
jdk.internal.joptsimple

public abstract Class ArgumentAcceptingOptionSpec<V>

extends AbstractOptionSpec<V>
Class Inheritance
Known Direct Subclasses
jdk.internal.joptsimple.OptionalArgumentOptionSpec, jdk.internal.joptsimple.RequiredArgumentOptionSpec, jdk.internal.joptsimple.AlternativeLongOptionSpec
Type Parameters
<V>
represents the type of the arguments this option accepts
Imports
java.util.ArrayList, .List, .StringTokenizer

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.

Author
Paul Holser

Field Summary

Modifier and TypeField and Description
private String
private final boolean
private ValueConverter<V>
private final List<V>
private static final char
private boolean
private String

Constructor Summary

AccessConstructor and Description
pack-priv
ArgumentAcceptingOptionSpec(String option, boolean argumentRequired)

pack-priv
ArgumentAcceptingOptionSpec(List<String> options, boolean argumentRequired, String description)

Method Summary

Modifier and TypeMethod and Description
public boolean
protected void
addArguments(OptionSet detectedOptions, String detectedArgument)

private void
addDefaultValue(V value)

public String
public String
argumentTypeIndicator()

Implements jdk.internal.joptsimple.OptionDescriptor.argumentTypeIndicator.

Gives an indication of the expected type of the option's argument.

protected boolean
protected final V
public final ArgumentAcceptingOptionSpec<V>

Returns:

self, so that the caller can add clauses to the fluent interface sentence
defaultsTo
(V
the first in the set of default argument values for this spec's option
value
,
V...
the (optional) remainder of the set of default argument values for this spec's option
values
)

Specifies a set of default values for the argument of the option that this spec represents.

public ArgumentAcceptingOptionSpec<V>

Returns:

self, so that the caller can add clauses to the fluent interface sentence
defaultsTo
(V[]
the set of default argument values for this spec's option
values
)

Specifies a set of default values for the argument of the option that this spec represents.

public List<V>
defaultValues()

Implements jdk.internal.joptsimple.OptionDescriptor.defaultValues.

What values will the option take if none are specified on the command line?

public final ArgumentAcceptingOptionSpec<V>

Returns:

self, so that the caller can add clauses to the fluent interface sentence
describedAs
(String
describes the nature of the argument of this spec's option
description
)

Specifies a description for the argument of the option that this spec represents.

protected abstract void
detectOptionArgument(OptionParser parser, ArgumentList arguments, OptionSet detectedOptions)

public boolean
equals(Object that)

Overrides jdk.internal.joptsimple.AbstractOptionSpec.equals.

Indicates whether some other object is "equal to" this one.

pack-priv final void
handleOption(OptionParser parser, ArgumentList arguments, OptionSet detectedOptions, String detectedArgument)

Implements abstract jdk.internal.joptsimple.AbstractOptionSpec.handleOption.

public int
hashCode()

Overrides jdk.internal.joptsimple.AbstractOptionSpec.hashCode.

Returns a hash code value for this object.

protected boolean
public boolean
isRequired()

Implements jdk.internal.joptsimple.OptionDescriptor.isRequired.

Is this option required on a command line?

public final <
represents the runtime class of the desired option argument type
T
>
ArgumentAcceptingOptionSpec<T>

Returns:

self, so that the caller can add clauses to the fluent interface sentence
ofType
(Class<T>
desired type of arguments to this spec's option
argumentType
)

Specifies a type to which arguments of this spec's option are to be converted.

public ArgumentAcceptingOptionSpec<V>

Returns:

self, so that the caller can add clauses to the fluent interface sentence
required
()

Marks this option as required.

public boolean
public final <
represents the runtime class of the desired option argument type
T
>
ArgumentAcceptingOptionSpec<T>

Returns:

self, so that the caller can add clauses to the fluent interface sentence
withValuesConvertedBy
(ValueConverter<T>
the converter to use
aConverter
)

Specifies a converter to use to translate arguments of this spec's option into Java objects.

public final ArgumentAcceptingOptionSpec<V>

Returns:

self, so that the caller can add clauses to the fluent interface sentence
withValuesSeparatedBy
(char
a character separator
separator
)

Specifies a value separator for the argument of the option that this spec represents.

public final ArgumentAcceptingOptionSpec<V>

Returns:

self, so that the caller can add clauses to the fluent interface sentence
withValuesSeparatedBy
(String
a string separator
separator
)

Specifies a value separator for the argument of the option that this spec represents.

Inherited from jdk.internal.joptsimple.AbstractOptionSpec:
argumentTypeIndicatorFromconvertWithdescriptionforHelpisForHelpoptionsrepresentsNonOptionstoStringvaluevalues

Field Detail

argumentDescriptionback to summary
private String argumentDescription
argumentRequiredback to summary
private final boolean argumentRequired
converterback to summary
private ValueConverter<V> converter
defaultValuesback to summary
private final List<V> defaultValues
NIL_VALUE_SEPARATORback to summary
private static final char NIL_VALUE_SEPARATOR
optionRequiredback to summary
private boolean optionRequired
valueSeparatorback to summary
private String valueSeparator

Constructor Detail

ArgumentAcceptingOptionSpecback to summary
pack-priv ArgumentAcceptingOptionSpec(String option, boolean argumentRequired)
ArgumentAcceptingOptionSpecback to summary
pack-priv ArgumentAcceptingOptionSpec(List<String> options, boolean argumentRequired, String description)

Method Detail

acceptsArgumentsback to summary
public boolean acceptsArguments()

Implements jdk.internal.joptsimple.OptionDescriptor.acceptsArguments.

Doc from jdk.internal.joptsimple.OptionDescriptor.acceptsArguments.

Does this option accept arguments?

addArgumentsback to summary
protected void addArguments(OptionSet detectedOptions, String detectedArgument)
addDefaultValueback to summary
private void addDefaultValue(V value)
argumentDescriptionback to summary
public String argumentDescription()

Implements jdk.internal.joptsimple.OptionDescriptor.argumentDescription.

Doc from jdk.internal.joptsimple.OptionDescriptor.argumentDescription.

Gives a short description of the option's argument.

argumentTypeIndicatorback to summary
public String argumentTypeIndicator()

Implements jdk.internal.joptsimple.OptionDescriptor.argumentTypeIndicator.

Doc from jdk.internal.joptsimple.OptionDescriptor.argumentTypeIndicator.

Gives an indication of the expected type of the option's argument.

canConvertArgumentback to summary
protected boolean canConvertArgument(String argument)
convertback to summary
protected final V convert(String argument)

Implements abstract jdk.internal.joptsimple.AbstractOptionSpec.convert.

Annotations
@Override
defaultsToback to summary
public final ArgumentAcceptingOptionSpec<V> defaultsTo(V value, V... values)

Specifies a set of default values for the argument of the option that this spec represents.

Parameters
value:V

the first in the set of default argument values for this spec's option

values:V[]

the (optional) remainder of the set of default argument values for this spec's option

Returns:ArgumentAcceptingOptionSpec<V>

self, so that the caller can add clauses to the fluent interface sentence

Annotations
@SafeVarargs
@SuppressWarnings:varargs
Exceptions
NullPointerException:
if value, values, or any elements of values are null
defaultsToback to summary
public ArgumentAcceptingOptionSpec<V> defaultsTo(V[] values)

Specifies a set of default values for the argument of the option that this spec represents.

Parameters
values:V[]

the set of default argument values for this spec's option

Returns:ArgumentAcceptingOptionSpec<V>

self, so that the caller can add clauses to the fluent interface sentence

Exceptions
NullPointerException:
if values or any elements of values are null
defaultValuesback to summary
public List<V> defaultValues()

Implements jdk.internal.joptsimple.OptionDescriptor.defaultValues.

Doc from jdk.internal.joptsimple.OptionDescriptor.defaultValues.

What values will the option take if none are specified on the command line?

describedAsback to summary
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.

Parameters
description:String

describes the nature of the argument of this spec's option

Returns:ArgumentAcceptingOptionSpec<V>

self, so that the caller can add clauses to the fluent interface sentence

detectOptionArgumentback to summary
protected abstract void detectOptionArgument(OptionParser parser, ArgumentList arguments, OptionSet detectedOptions)
equalsback to summary
public boolean equals(Object that)

Overrides jdk.internal.joptsimple.AbstractOptionSpec.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Annotations
@Override
handleOptionback to summary
pack-priv final void handleOption(OptionParser parser, ArgumentList arguments, OptionSet detectedOptions, String detectedArgument)

Implements abstract jdk.internal.joptsimple.AbstractOptionSpec.handleOption.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides jdk.internal.joptsimple.AbstractOptionSpec.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Annotations
@Override
isArgumentOfNumberTypeback to summary
protected boolean isArgumentOfNumberType()
isRequiredback to summary
public boolean isRequired()

Implements jdk.internal.joptsimple.OptionDescriptor.isRequired.

Doc from jdk.internal.joptsimple.OptionDescriptor.isRequired.

Is this option required on a command line?

ofTypeback to summary
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:

  1. a public static method called 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.
  2. a public constructor which accepts a single argument of type 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).

Parameters
<T>
represents the runtime class of the desired option argument type
argumentType:Class<T>

desired type of arguments to this spec's option

Returns:ArgumentAcceptingOptionSpec<T>

self, so that the caller can add clauses to the fluent interface sentence

Exceptions
NullPointerException:
if the type is null
IllegalArgumentException:
if the type does not have the standard conversion methods
requiredback to summary
public ArgumentAcceptingOptionSpec<V> required()

Marks this option as required. An OptionException will be thrown when OptionParser#parse(java.lang.String...) is called, if an option is marked as required and not specified on the command line.

Returns:ArgumentAcceptingOptionSpec<V>

self, so that the caller can add clauses to the fluent interface sentence

requiresArgumentback to summary
public boolean requiresArgument()

Implements jdk.internal.joptsimple.OptionDescriptor.requiresArgument.

Doc from jdk.internal.joptsimple.OptionDescriptor.requiresArgument.

Does this option require an argument?

withValuesConvertedByback to summary
public 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).

Parameters
<T>
represents the runtime class of the desired option argument type
aConverter:ValueConverter<T>

the converter to use

Returns:ArgumentAcceptingOptionSpec<T>

self, so that the caller can add clauses to the fluent interface sentence

Annotations
@SuppressWarnings:unchecked
Exceptions
NullPointerException:
if the converter is null
withValuesSeparatedByback to summary
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.

Parameters
separator:char

a character separator

Returns:ArgumentAcceptingOptionSpec<V>

self, so that the caller can add clauses to the fluent interface sentence

Exceptions
IllegalArgumentException:
if the separator is Unicode U+0000
withValuesSeparatedByback to summary
public final ArgumentAcceptingOptionSpec<V> withValuesSeparatedBy(String 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 in the separator.

Parameters
separator:String

a string separator

Returns:ArgumentAcceptingOptionSpec<V>

self, so that the caller can add clauses to the fluent interface sentence

Exceptions
IllegalArgumentException:
if the separator contains Unicode U+0000