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

public Class OptionSet

extends Object
Class Inheritance
Imports
java.util.ArrayList, .HashMap, .IdentityHashMap, .List, .Map

Representation of a group of detected command line options, their arguments, and non-option arguments.
Author
Paul Holser

Field Summary

Modifier and TypeField and Description
private final Map<String, List<?>>
private final Map<String, AbstractOptionSpec<?>>
private final List<OptionSpec<?>>
private final Map<AbstractOptionSpec<?>, List<String>>
private final Map<String, AbstractOptionSpec<?>>

Constructor Summary

AccessConstructor and Description
pack-priv
OptionSet(Map<String, AbstractOptionSpec<?>> recognizedSpecs)

Method Summary

Modifier and TypeMethod and Description
pack-priv void
pack-priv void
public Map<OptionSpec<?>, List<?>>

Returns:

the declared options as a map
asMap
()

Gives all declared options as a map of string to OptionSpec.

private <V> List<V>
private static Map<String, List<?>>
private <V> List<V>
public boolean
equals(Object that)

Overrides java.lang.Object.equals.

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

public boolean

Returns:

true if the option was detected
has
(String
the option to search for
option
)

Tells whether the given option was detected.

public boolean

Returns:

true if the option was detected
has
(OptionSpec<?>
the option to search for
option
)

Tells whether the given option was detected.

public boolean

Returns:

true if the option was detected and at least one argument was detected for the option
hasArgument
(String
the option to search for
option
)

Tells whether there are any arguments associated with the given option.

public boolean

Returns:

true if the option was detected and at least one argument was detected for the option
hasArgument
(OptionSpec<?>
the option to search for
option
)

Tells whether there are any arguments associated with the given option.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public boolean

Returns:

true if any options were detected
hasOptions
()

Tells whether any options were detected.

public List<?>
nonOptionArguments()

Returns: the detected non-option arguments

public List<OptionSpec<?>>

Returns:

the set of detected command line options
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.

public Object

Returns:

the argument of the given option; null if no argument is present, or that option was not detected
valueOf
(String
the option to search for
option
)

Gives the argument associated with the given option.

public <
represents the type of the arguments the given option accepts
V
>
V

Returns:

the argument of the given option; null if no argument is present, or that option was not detected
valueOf
(OptionSpec<V>
the option to search for
option
)

Gives the argument associated with the given option.

public List<?>

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
valuesOf
(String
the option to search for
option
)

Gives any arguments associated with the given option.

public <
represents the type of the arguments the given option accepts
V
>
List<V>

Returns:

the arguments associated with the option; an empty list if no such arguments are present, or if the option was not detected
valuesOf
(OptionSpec<V>
the option to search for
option
)

Gives any arguments associated with the given option.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

defaultValuesback to summary
private final Map<String, List<?>> defaultValues
detectedOptionsback to summary
private final Map<String, AbstractOptionSpec<?>> detectedOptions
detectedSpecsback to summary
private final List<OptionSpec<?>> detectedSpecs
optionsToArgumentsback to summary
private final Map<AbstractOptionSpec<?>, List<String>> optionsToArguments
recognizedSpecsback to summary
private final Map<String, AbstractOptionSpec<?>> recognizedSpecs

Constructor Detail

OptionSetback to summary
pack-priv OptionSet(Map<String, AbstractOptionSpec<?>> recognizedSpecs)

Method Detail

addback to summary
pack-priv void add(AbstractOptionSpec<?> spec)
addWithArgumentback to summary
pack-priv void addWithArgument(AbstractOptionSpec<?> spec, String argument)
asMapback to summary
public Map<OptionSpec<?>, List<?>> asMap()

Gives all declared options as a map of string to OptionSpec.

Returns:Map<OptionSpec<?>, List<?>>

the declared options as a map

defaultValueForback to summary
private <V> List<V> defaultValueFor(OptionSpec<V> option)
defaultValuesback to summary
private static Map<String, List<?>> defaultValues(Map<String, AbstractOptionSpec<?>> recognizedSpecs)
defaultValuesForback to summary
private <V> List<V> defaultValuesFor(String option)
Annotations
@SuppressWarnings:unchecked
equalsback to summary
public boolean equals(Object that)

Overrides java.lang.Object.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
hasback to summary
public boolean has(String option)

Tells whether the given option was detected.

Parameters
option:String

the option to search for

Returns:boolean

true if the option was detected

See Also
has(OptionSpec)
hasback to summary
public boolean has(OptionSpec<?> option)

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 true if the option was not detected on the command line.

Parameters
option:OptionSpec<?>

the option to search for

Returns:boolean

true if the option was detected

See Also
has(String)
hasArgumentback to summary
public boolean hasArgument(String option)

Tells whether there are any arguments associated with the given option.

Parameters
option:String

the option to search for

Returns:boolean

true if the option was detected and at least one argument was detected for the option

See Also
hasArgument(OptionSpec)
hasArgumentback to summary
public boolean hasArgument(OptionSpec<?> option)

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 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.

Parameters
option:OptionSpec<?>

the option to search for

Returns:boolean

true if the option was detected and at least one argument was detected for the option

Exceptions
NullPointerException:
if option is null
See Also
hasArgument(String)
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.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
hasOptionsback to summary
public boolean hasOptions()

Tells whether any options were detected.

Returns:boolean

true if any options were detected

nonOptionArgumentsback to summary
public List<?> nonOptionArguments()
Returns:List<?>

the detected non-option arguments

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

Returns:List<OptionSpec<?>>

the set of detected command line options

valueOfback to summary
public Object valueOf(String option)

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 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.

Parameters
option:String

the option to search for

Returns:Object

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

Exceptions
NullPointerException:
if option is null
OptionException:
if more than one argument was detected for the option
valueOfback to summary
public <V> V valueOf(OptionSpec<V> option)

Gives the argument associated with the given option.

This method recognizes only instances of options returned from the fluent interface methods.

Parameters
<V>
represents the type of the arguments the given option accepts
option:OptionSpec<V>

the option to search for

Returns:V

the argument of the given 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 option is null
ClassCastException:
if the arguments of this option are not of the expected type
valuesOfback to summary
public 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 Strings.

Parameters
option:String

the option to search for

Returns:List<?>

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

Exceptions
NullPointerException:
if option is null
valuesOfback to summary
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 Strings.

This method recognizes only instances of options returned from the fluent interface methods.

Parameters
<V>
represents the type of the arguments the given option accepts
option:OptionSpec<V>

the option to search for

Returns:List<V>

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

Exceptions
NullPointerException:
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 method