Package com.martiansoftware.jsap
Class Switch
java.lang.Object
com.martiansoftware.jsap.Parameter
com.martiansoftware.jsap.Switch
- All Implemented Interfaces:
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:
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new Switch with the specified unique ID.A shortcut constructor that creates a new Switch and configures all of its settings.A shortcut constructor that creates a new Switch and configures all of its settings, including help. -
Method Summary
Modifier and TypeMethodDescriptionReturns the long flag for this Switch.char
Returns the short flag for this Switch.Returns the short flag for this Switch.Returns usage instructions for this Switch.setDefault
(String defaultValue) Sets a default value for this parameter.setDefault
(String[] defaultValues) Sets one or more default values for this parameter.setLongFlag
(String longFlag) Sets the long flag for this 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
-
Constructor Details
-
Switch
Creates a new Switch with the specified unique ID.- Parameters:
id
- the unique ID for this Switch.
-
Switch
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 toJSAP.NO_HELP
for none).
-
Switch
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 Details
-
setShortFlag
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 interfaceFlagged
- 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
Returns the short flag for this Switch. If this Switch has no short flag, the return value will be null.- Specified by:
getShortFlagCharacter
in interfaceFlagged
- Returns:
- the short flag for this Switch. If this Switch has no short flag, the return value will be null.
-
setLongFlag
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
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 interfaceFlagged
- 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
Returns usage instructions for this Switch. -
setDefault
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
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:
-