joptsimple
Class NonOptionArgumentSpec<V>

java.lang.Object
  extended by joptsimple.NonOptionArgumentSpec<V>
Type Parameters:
V - represents the type of the non-option arguments
All Implemented Interfaces:
OptionDescriptor, OptionSpec<V>

public class NonOptionArgumentSpec<V>
extends Object

Specification of a command line's non-option arguments.

Instances are returned from OptionParser methods to allow the formation of parser directives as sentences in a "fluent interface" language. For example:

   
   OptionParser parser = new OptionParser();
   parser.nonOptions( "files to be processed" ).ofType( File.class );
   
 

If no methods are invoked on an instance of this class, then that instance's option will treat the non-option arguments as Strings.

Author:
Paul Holser

Method Summary
 boolean acceptsArguments()
          Does this option accept arguments?
 String argumentDescription()
          Gives a short description of the option's argument.
 String argumentTypeIndicator()
          Gives an indication of the expected type of the option's argument.
protected  String argumentTypeIndicatorFrom(ValueConverter<V> converter)
           
protected  V convert(String argument)
           
protected  V convertWith(ValueConverter<V> converter, String argument)
           
 List<?> defaultValues()
          What values will the option take if none are specified on the command line?
 NonOptionArgumentSpec<V> describedAs(String description)
          Specifies a description for the non-option arguments that this spec represents.
 String description()
          Description of this option's purpose.
 boolean equals(Object that)
           
 joptsimple.AbstractOptionSpec<V> forHelp()
           
 int hashCode()
           
 boolean isForHelp()
          Tells whether this option is designated as a "help" option.
 boolean isRequired()
          Is this option required on a command line?
<T> NonOptionArgumentSpec<T>
ofType(Class<T> argumentType)
          Specifies a type to which the non-option arguments are to be converted.
 Collection<String> options()
          A set of options that are mutually synonymous.
 boolean representsNonOptions()
          Tells whether this object represents the non-option arguments of a command line.
 boolean requiresArgument()
          Does this option require an argument?
 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.
<T> NonOptionArgumentSpec<T>
withValuesConvertedBy(ValueConverter<T> aConverter)
          Specifies a converter to use to translate non-option arguments into Java objects.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

ofType

public <T> NonOptionArgumentSpec<T> ofType(Class<T> argumentType)

Specifies a type to which the non-option arguments 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).

Type Parameters:
T - represents the runtime class of the desired option argument type
Parameters:
argumentType - desired type of arguments to this spec's option
Returns:
self, so that the caller can add clauses to the fluent interface sentence
Throws:
NullPointerException - if the type is null
IllegalArgumentException - if the type does not have the standard conversion methods

withValuesConvertedBy

public final <T> NonOptionArgumentSpec<T> withValuesConvertedBy(ValueConverter<T> aConverter)

Specifies a converter to use to translate non-option arguments 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).

Type Parameters:
T - represents the runtime class of the desired non-option argument type
Parameters:
aConverter - the converter to use
Returns:
self, so that the caller can add clauses to the fluent interface sentence
Throws:
NullPointerException - if the converter is null

describedAs

public NonOptionArgumentSpec<V> describedAs(String description)

Specifies a description for the non-option arguments that this spec represents. This description is used when generating help information about the parser.

Parameters:
description - describes the nature of the argument of this spec's option
Returns:
self, so that the caller can add clauses to the fluent interface sentence

convert

protected final V convert(String argument)

defaultValues

public List<?> defaultValues()
Description copied from interface: OptionDescriptor
What values will the option take if none are specified on the command line?

Returns:
any default values for the option

isRequired

public boolean isRequired()
Description copied from interface: OptionDescriptor
Is this option required on a command line?

Returns:
whether the option is required

acceptsArguments

public boolean acceptsArguments()
Description copied from interface: OptionDescriptor
Does this option accept arguments?

Returns:
whether the option accepts arguments

requiresArgument

public boolean requiresArgument()
Description copied from interface: OptionDescriptor
Does this option require an argument?

Returns:
whether the option requires an argument

argumentDescription

public String argumentDescription()
Description copied from interface: OptionDescriptor
Gives a short description of the option's argument.

Returns:
a description for the option's argument

argumentTypeIndicator

public String argumentTypeIndicator()
Description copied from interface: OptionDescriptor
Gives an indication of the expected type of the option's argument.

Returns:
a description for the option's argument type

representsNonOptions

public boolean representsNonOptions()
Description copied from interface: OptionDescriptor
Tells whether this object represents the non-option arguments of a command line.

Specified by:
representsNonOptions in interface OptionDescriptor
Returns:
true if this represents non-option arguments

options

public final Collection<String> options()
Description copied from interface: OptionDescriptor
A set of options that are mutually synonymous.

Specified by:
options in interface OptionDescriptor
Specified by:
options in interface OptionSpec<V>
Returns:
the string representations of this option

values

public final List<V> values(OptionSet detectedOptions)
Description copied from interface: 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.

Specified by:
values in interface OptionSpec<V>
Parameters:
detectedOptions - the detected options to search in
Returns:
the arguments associated with this option; an empty list if no such arguments are present, or if this option was not detected
See Also:
OptionSet.valuesOf(OptionSpec)

value

public final V value(OptionSet detectedOptions)
Description copied from interface: 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.

Specified by:
value in interface OptionSpec<V>
Parameters:
detectedOptions - the detected options to search in
Returns:
the argument of the this option; null if no argument is present, or that option was not detected
See Also:
OptionSet.valueOf(OptionSpec)

description

public String description()
Description copied from interface: OptionDescriptor
Description of this option's purpose.

Specified by:
description in interface OptionDescriptor
Returns:
a description for the option

forHelp

public final joptsimple.AbstractOptionSpec<V> forHelp()

isForHelp

public final boolean isForHelp()
Description copied from interface: OptionSpec
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.

Specified by:
isForHelp in interface OptionSpec<V>
Returns:
whether this option is designated as a "help" option

convertWith

protected V convertWith(ValueConverter<V> converter,
                        String argument)

argumentTypeIndicatorFrom

protected String argumentTypeIndicatorFrom(ValueConverter<V> converter)

equals

public boolean equals(Object that)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2014. All Rights Reserved.