Parameter (JSAP: the Java Simple Argument Parser)
Keywords: com.martiansoftware.jsap.Parameter class

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.martiansoftware.jsap
Class Parameter

    java.lang.Object
      com.martiansoftware.jsap.Parameter

Direct Known Subclasses:
  Option, Switch

    public abstract class Parameter

extends Object

Top-level abstraction of a parameter. A parameter consists of one or more arguments (command line tokens) that have a special meaning when taken together. For example, a command-line switch "-v" is a parameter consisting of a single argument, whereas a command-line option "--file somefile.txt" is a parameter consisting of two arguments. Some parameters can be quite large, such as an option for a file compression utility that allows you to specify any number of files to comporess.

This is an abstract class. See its subclasses `Switch`, `FlaggedOption`, and `UnflaggedOption` for details on the various types of parameters. Functionality common to all three types of Parameters is described below.

Each parameter has a unique ID assigned in its constructor. This ID is used to retrieve values from the parser after the command line is parsed. You can set the ID to any String value you wish, although in general you'll want them to be brief and descriptive to provide a degree of documentation. A "-h" switch, for example, might have the ID "help". The calling program can then determine if the user specified the -h switch on the command line with the simple call `getBoolean("help")` against the JSAPResult object produced by JSAP.parse().

Author:
  Marty Lamb
See Also:
  `Switch`, `FlaggedOption`, `UnflaggedOption`, `JSAPResult.getBoolean(String)`, `JSAP.parse(String[])`

Constructor Summary
`Parameter(String id)` Creates a new Parameter.

Method Summary
`void` | `addDefault(String defaultValue)` Adds a single default value to any currently defined for this parameter.
`String[]` | `getDefault()` Returns an array of default values for this parameter, or null if no default values have been defined.
`String` | `getHelp()` Returns a description of the option's usage.
`String` | `getID()` Returns this parameter's unique ID.
`abstract String` | `getSyntax()` A convenience method for automatically generating syntax information based upon a JSAP configuration.
`String` | `getUsage()` Deprecated. use getSyntax() instead
`String` | `getUsageName()` Returns the name of this AbstractParameter for the purposes of usage information.
`Parameter` | `setHelp(String help)` Sets the help text for this parameter.

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### Parameter

    public Parameter(String id)

  Creates a new Parameter. Subclasses should call this constructor.

  Parameters:
    `id` - The ID for this argument. All arguments MUST have a unique ID.

Method Detail

### getID

    public String getID()

  Returns this parameter's unique ID.

  Returns:
    this parameter's unique ID.

### addDefault

    public final void addDefault(String defaultValue)

  Adds a single default value to any currently defined for this parameter.

  Parameters:
    `defaultValue` - the default value to add to this parameter.

### getUsageName

    public final String getUsageName()

  Returns the name of this AbstractParameter for the purposes of usage information. The returned value is by default the id of this parameter, but can be overridden via setUsageName(String).

  Returns:
    the name of this AbstractParameter for the purposes of usage information.

### getDefault

    public final String[] getDefault()

  Returns an array of default values for this parameter, or null if no default values have been defined.

  Returns:
    an array of default values for this parameter, or null if no default values have been defined.

### getSyntax

    public abstract String getSyntax()

  A convenience method for automatically generating syntax information based upon a JSAP configuration. A call to JSAP.getSyntax() returns a String built by calling getSyntax() on every parameter registered to a JSAP in the order in which they were registered. This method does not provide a help description (see getHelp()), but rather the syntax for this parameter.

  Returns:
    usage information for this parameter.

### getUsage

    public final String getUsage()

  Deprecated. use getSyntax() instead

  Deprecated - use getSyntax()

  Returns:
    deprecated - use getSyntax()

### getHelp

    public final String getHelp()

  Returns a description of the option's usage.

  Returns:
    a textual description of this option's usage

### setHelp

    public final Parameter setHelp(String help)

  Sets the help text for this parameter.

  Parameters:
    `help` - the help text for this parameter.

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2002-2005, Martian Software, Inc.. All Rights Reserved.
For the latest version and documentation, please visit http://www.martiansoftware.com/jsap