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

    java.lang.Object
      com.martiansoftware.jsap.Parameter
          com.martiansoftware.jsap.Option
              com.martiansoftware.jsap.FlaggedOption
                  com.martiansoftware.jsap.QualifiedSwitch

All Implemented Interfaces:
  Flagged

    public final class QualifiedSwitch

extends FlaggedOption

A QualifiedSwitch is a parameter that has something in common with a Switch, i.e., its presence or absence is significant, but different from a "pure" Switch it can have an additional value (or values) prefixed by a ':' sign that qualifies the Switch - making it behave like a FlaggedOption if a value is specified.

QualifiedSwitch in fact extends FlaggedOption, providing all of its functionality including the ability to use any StringParser to parse its optional value(s). Values are retrieved from the JSAPResult in the same manner they would be retrieved for an equivalent FlaggedOption.

Additionally, the QualifiedSwitch's presence on the command line can be determined via JSAPResult.getBoolean(id). This presents a small challenge in the unlikely event that you're also using a BooleanStringParser with the QualifiedSwitch; if you are, JSAPResult.getBoolean(id) will not return the optional values, but will still signify the QualifiedSwitch's presence. Boolean optional values can be retrieved via JSAPResult.getBooleanArray(id). The first boolean in the array will be the first optionally specified boolean value qualifying the switch.

The following are some examples of a QualifiedSwitch's use:

- -s:value is a QualifiedSwitch with only one qualifying value.
- -s has no qualifying value.
- --qswitch:a,b,c (configured with `setList(true)` and `setListSeparator(',')`) has three qualifying values.

Please note that QualifiedSwitch is currently experimental, although it has no known problems.

QualifiedSwitch and its supporting code in other JSAP classes was generously contributed to JSAP by Klaus P. Berg of Siemens AG, Munich, Germany.

Since:
  1.03
Author:
  Klaus P. Berg, Siemens AG, Munich, Germany, Marty Lamb

Constructor Summary
`QualifiedSwitch(String id)` A shortcut constructor that creates a new QualifiedSwitch
`QualifiedSwitch(String id, StringParser stringParser, String defaultValue, boolean required, char shortFlag, String longFlag)` A shortcut constructor that creates a new QualifiedSwitch and configures its most commonly used settings.
`QualifiedSwitch(String id, StringParser stringParser, String defaultValue, boolean required, char shortFlag, String longFlag, String help)` A shortcut constructor that creates a new QualifiedSwitch and configures its most commonly used settings, including help.

Method Summary
`String` | `getSyntax()` Returns syntax instructions for this QualifiedSwitch.

Methods inherited from class com.martiansoftware.jsap.FlaggedOption
`allowMultipleDeclarations, getLongFlag, getShortFlag, getShortFlagCharacter, setAllowMultipleDeclarations, setDefault, setDefault, setList, setListSeparator, setLongFlag, setRequired, setShortFlag, setStringParser, setUsageName`

Methods inherited from class com.martiansoftware.jsap.Option
`getListSeparator, getStringParser, isList, required`

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

### QualifiedSwitch

    public QualifiedSwitch(String id,
                           StringParser stringParser,
                           String defaultValue,
                           boolean required,
                           char shortFlag,
                           String longFlag,
                           String help)

  A shortcut constructor that creates a new QualifiedSwitch and configures its most commonly used settings, including help.

  Parameters:
    `id` - the unique ID for this FlaggedOption.
    `stringParser` - the StringParser this FlaggedOption should use.
    `defaultValue` - the default value for this FlaggedOption (may be null).
    `required` - if true, this FlaggedOption is required.
    `shortFlag` - the short flag for this option (may be set to JSAP.NO_SHORTFLAG for none).
    `longFlag` - the long flag for this option (may be set to JSAP.NO_LONGFLAG for none).
    `help` - the help text for this option (may be set to `JSAP.NO_HELP` for none).

### QualifiedSwitch

    public QualifiedSwitch(String id,
                           StringParser stringParser,
                           String defaultValue,
                           boolean required,
                           char shortFlag,
                           String longFlag)

  A shortcut constructor that creates a new QualifiedSwitch and configures its most commonly used settings.

  Parameters:
    `id` - the unique ID for this FlaggedOption.
    `stringParser` - the StringParser this FlaggedOption should use.
    `defaultValue` - the default value for this FlaggedOption (may be null).
    `required` - if true, this FlaggedOption is required.
    `shortFlag` - the short flag for this option (may be set to JSAP.NO_SHORTFLAG for none).
    `longFlag` - the long flag for this option (may be set to JSAP.NO_LONGFLAG for none).

### QualifiedSwitch

    public QualifiedSwitch(String id)

  A shortcut constructor that creates a new QualifiedSwitch

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

Method Detail

### getSyntax

    public String getSyntax()

  Returns syntax instructions for this QualifiedSwitch.

  Overrides:
    `getSyntax` in class `FlaggedOption`
  Returns:
    syntax instructions for this QualifiedSwitch based upon its current configuration.

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