Package 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 aBooleanStringParser
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
Constructors Constructor Description Switch(java.lang.String id)
Creates a new Switch with the specified unique ID.Switch(java.lang.String id, char shortFlag, java.lang.String longFlag)
A shortcut constructor that creates a new Switch and configures all of its settings.Switch(java.lang.String id, char shortFlag, java.lang.String longFlag, java.lang.String help)
A shortcut constructor that creates a new Switch and configures all of its settings, including help.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
getLongFlag()
Returns the long flag for this Switch.char
getShortFlag()
Returns the short flag for this Switch.java.lang.Character
getShortFlagCharacter()
Returns the short flag for this Switch.java.lang.String
getSyntax()
Returns usage instructions for this Switch.Switch
setDefault(java.lang.String defaultValue)
Sets a default value for this parameter.Switch
setDefault(java.lang.String[] defaultValues)
Sets one or more default values for this parameter.Switch
setLongFlag(java.lang.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
-
-
-
-
Constructor Detail
-
Switch
public Switch(java.lang.String id)
Creates a new Switch with the specified unique ID.- Parameters:
id
- the unique ID for this Switch.
-
Switch
public Switch(java.lang.String id, char shortFlag, java.lang.String longFlag, java.lang.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 toJSAP.NO_HELP
for none).
-
Switch
public Switch(java.lang.String id, char shortFlag, java.lang.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 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
public java.lang.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 interfaceFlagged
- Returns:
- the short flag for this Switch. If this Switch has no short flag, the return value will be null.
-
setLongFlag
public Switch setLongFlag(java.lang.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 java.lang.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 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
public java.lang.String getSyntax()
Returns usage instructions for this Switch.
-
setDefault
public Switch setDefault(java.lang.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(java.lang.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)
-
-