Switch (JSAP: the Java Simple Argument Parser)
Keywords: com.martiansoftware.jsap.Switch 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 Switch

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

All Implemented Interfaces:
  Flagged

    public class Switch

extends Parameter
implements Flagged

A Switch is a parameter whose presence alone is significant; another commonly used term for a Switch is "Flag". Switches use a `BooleanStringParser` internally, so their results can be obtained from a JSAPResult using the getBoolean() methods.

An example of a command line using a Switch is "dosomething -v", where "-v" might mean "verbose."

Author:
  Marty Lamb
See Also:
  `Flagged`, `BooleanStringParser`

Constructor Summary
`Switch(String id)` Creates a new Switch with the specified unique ID.
`Switch(String id, char shortFlag, String longFlag)` A shortcut constructor that creates a new Switch and configures all of its settings.
`Switch(String id, char shortFlag, String longFlag, String help)` A shortcut constructor that creates a new Switch and configures all of its settings, including help.

Method Summary
`String` | `getLongFlag()` Returns the long flag for this Switch.
`char` | `getShortFlag()` Returns the short flag for this Switch.
`Character` | `getShortFlagCharacter()` Returns the short flag for this Switch.
`String` | `getSyntax()` Returns usage instructions for this Switch.
`Switch` | `setDefault(String defaultValue)` Sets a default value for this parameter.
`Switch` | `setDefault(String[] defaultValues)` Sets one or more default values for this parameter.
`Switch` | `setLongFlag(String longFlag)` Sets the long flag for this Switch.
`Switch` | `setShortFlag(char shortFlag)` Sets the short flag for this Switch.

Methods inherited from class com.martiansoftware.jsap.Parameter
`addDefault, getDefault, getHelp, getID, getUsage, getUsageName, setHelp`

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

Constructor Detail

### Switch

    public Switch(String id)

  Creates a new Switch with the specified unique ID.

  Parameters:
    `id` - the unique ID for this Switch.

### Switch

    public Switch(String id,
                  char shortFlag,
                  String longFlag,
                  String help)

  A shortcut constructor that creates a new Switch and configures all of its settings, including help.

  Parameters:
    `id` - the unique ID for this Switch.
    `shortFlag` - the short flag for this Switch (may be set to JSAP.NO_SHORTFLAG for none).
    `longFlag` - the long flag for this Switch (may be set to JSAP.NO_LONGFLAG for none).
    `help` - the help text for this Switch (may be set to `JSAP.NO_HELP`for none).

### Switch

    public Switch(String id,
                  char shortFlag,
                  String longFlag)

  A shortcut constructor that creates a new Switch and configures all of its settings.

  Parameters:
    `id` - the unique ID for this Switch.
    `shortFlag` - the short flag for this Switch (may be set to JSAP.NO_SHORTFLAG for none).
    `longFlag` - the long flag for this Switch (may be set to JSAP.NO_LONGFLAG for none).

Method Detail

### setShortFlag

    public Switch setShortFlag(char shortFlag)

  Sets the short flag for this Switch. To use no short flag at all, set the value to JSAP.NO_SHORTFLAG.

  Parameters:
    `shortFlag` - the short flag for this Switch.
  Returns:
    the modified Switch

### getShortFlag

    public char getShortFlag()

  Returns the short flag for this Switch. If this Switch has no short flag, the return value will be equal to JSAP.NO_SHORTFLAG.

  Specified by:
    `getShortFlag` in interface `Flagged`
  Returns:
    the short flag for this Switch. If this Switch has no short flag, the return value will be equal to JSAP.NO_SHORTFLAG.

### getShortFlagCharacter

    public Character getShortFlagCharacter()

  Returns the short flag for this Switch. If this Switch has no short flag, the return value will be null.

  Specified by:
    `getShortFlagCharacter` in interface `Flagged`
  Returns:
    the short flag for this Switch. If this Switch has no short flag, the return value will be null.

### setLongFlag

    public Switch setLongFlag(String longFlag)

  Sets the long flag for this Switch. To use no long flag at all, set the value to JSAP.NO_LONGFLAG.

  Parameters:
    `longFlag` - the long flag for this Switch.
  Returns:
    the modified Switch

### getLongFlag

    public String getLongFlag()

  Returns the long flag for this Switch. If this Switch has no long flag, the return value will be equal to JSAP.NO_LONGFLAG.

  Specified by:
    `getLongFlag` in interface `Flagged`
  Returns:
    the long flag for this FlaggedOption. If this FlaggedOption has no long flag, the return value will be equal to JSAP.NO_LONGFLAG.

### getSyntax

    public String getSyntax()

  Returns usage instructions for this Switch.

  Specified by:
    `getSyntax` in class `Parameter`
  Returns:
    usage instructions for this Switch based upon its current configuration.

### setDefault

    public Switch setDefault(String defaultValue)

  Sets a default value for this parameter. The default is specified as a String, and is parsed as a single value specified on the command line. In other words, default values for "list" parameters or parameters allowing multiple declarations should be set using setDefault(String[]), as JSAP would otherwise treat the entire list of values as a single value.

  Parameters:
    `defaultValue` - the default value for this parameter.
  See Also:
    `setDefault(String)`

### setDefault

    public Switch setDefault(String[] defaultValues)

  Sets one or more default values for this parameter. This method should be used whenever a parameter has more than one default value.

  Parameters:
    `defaultValues` - the default values for this parameter.
  See Also:
    `setDefault(String)`

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