Package com.martiansoftware.jsap
Class FlaggedOption
- java.lang.Object
-
- com.martiansoftware.jsap.Parameter
-
- com.martiansoftware.jsap.Option
-
- com.martiansoftware.jsap.FlaggedOption
-
- All Implemented Interfaces:
Flagged
- Direct Known Subclasses:
QualifiedSwitch
public class FlaggedOption extends Option implements Flagged
An option that implements the Flagged interface. A flagged option is preceded by a short flag or a long flag; i.e. "-n 5" or "--number 5". FlaggedOptions also provide an additional features over unflagged options, namely the ability to be declared more than once in a command line (e.g., "-n 5 -n 10"). This is not possible with unflagged options, as they are never declared.- Author:
- Marty Lamb
- See Also:
Flagged
,Option
-
-
Constructor Summary
Constructors Constructor Description FlaggedOption(java.lang.String id)
Creates a new FlaggedOption with the specified unique ID.FlaggedOption(java.lang.String id, StringParser stringParser, java.lang.String defaultValue, boolean required, char shortFlag, java.lang.String longFlag)
A shortcut constructor that creates a new FlaggedOption and configures its most commonly used settings.FlaggedOption(java.lang.String id, StringParser stringParser, java.lang.String defaultValue, boolean required, char shortFlag, java.lang.String longFlag, java.lang.String help)
A shortcut constructor that creates a new FlaggedOption and configures its most commonly used settings, including help.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
allowMultipleDeclarations()
Returns a boolean indicating whether multiple declarations are allowed for this FlaggedOption.java.lang.String
getLongFlag()
Returns the long flag for this FlaggedOption.char
getShortFlag()
Returns the short flag for this FlaggedOption.java.lang.Character
getShortFlagCharacter()
Returns the short flag for this FlaggedOption.java.lang.String
getSyntax()
Returns syntax instructions for this FlaggedOption.FlaggedOption
setAllowMultipleDeclarations(boolean allowMultipleDeclarations)
Sets this FlaggedOption to allow or disallow multiple declarations.FlaggedOption
setDefault(java.lang.String defaultValue)
Sets a default value for this parameter.FlaggedOption
setDefault(java.lang.String[] defaultValues)
Sets one or more default values for this parameter.FlaggedOption
setList(boolean isList)
Sets whether this FlaggedOption is a list.FlaggedOption
setListSeparator(char listSeparator)
Sets the list separator character for this FlaggedOption.FlaggedOption
setLongFlag(java.lang.String longFlag)
Sets the long flag for this FlaggedOption.FlaggedOption
setRequired(boolean required)
Sets whether this FlaggedOption is required.FlaggedOption
setShortFlag(char shortFlag)
Sets the short flag for this FlaggedOption.FlaggedOption
setStringParser(StringParser stringParser)
Sets the StringParser to which this FlaggedOption's parse() method should delegate.FlaggedOption
setUsageName(java.lang.String usageName)
Sets the name that will be displayed when getSyntax() is called-
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
-
-
-
-
Constructor Detail
-
FlaggedOption
public FlaggedOption(java.lang.String id)
Creates a new FlaggedOption with the specified unique ID.- Parameters:
id
- the unique ID for this FlaggedOption.
-
FlaggedOption
public FlaggedOption(java.lang.String id, StringParser stringParser, java.lang.String defaultValue, boolean required, char shortFlag, java.lang.String longFlag, java.lang.String help)
A shortcut constructor that creates a new FlaggedOption 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 toJSAP.NO_HELP
for none).
-
FlaggedOption
public FlaggedOption(java.lang.String id, StringParser stringParser, java.lang.String defaultValue, boolean required, char shortFlag, java.lang.String longFlag)
A shortcut constructor that creates a new FlaggedOption 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).
-
-
Method Detail
-
setShortFlag
public FlaggedOption setShortFlag(char shortFlag)
Sets the short flag for this FlaggedOption. To use no short flag at all, set the value to JSAP.NO_SHORTFLAG.- Parameters:
shortFlag
- the short flag for this FlaggedOption.- Returns:
- the modified FlaggedOption
-
getShortFlag
public char getShortFlag()
Returns the short flag for this FlaggedOption. If this FlaggedOption 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 FlaggedOption. If this FlaggedOption 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 FlaggedOption. If this FlaggedOption has no short flag, the return value will be null.- Specified by:
getShortFlagCharacter
in interfaceFlagged
- Returns:
- the short flag for this FlaggedOption. If this FlaggedOption has no short flag, the return value will be null.
-
setLongFlag
public FlaggedOption setLongFlag(java.lang.String longFlag)
Sets the long flag for this FlaggedOption. To use no long flag at all, set the value to JSAP.NO_LONGFLAG.- Parameters:
longFlag
- the long flag for this FlaggedOption.- Returns:
- the modified FlaggedOption
-
setUsageName
public FlaggedOption setUsageName(java.lang.String usageName)
Sets the name that will be displayed when getSyntax() is called- Parameters:
usageName
- the name to use, or null if the id should be used (default)- Returns:
- the modified FlaggedOption
-
getLongFlag
public java.lang.String getLongFlag()
Returns the long flag for this FlaggedOption. If this FlaggedOption 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.
-
setAllowMultipleDeclarations
public FlaggedOption setAllowMultipleDeclarations(boolean allowMultipleDeclarations)
Sets this FlaggedOption to allow or disallow multiple declarations. If multiple declarations are allowed, the flag may be specified multiple times on the command line (e.g., "-n 5 -n 10"). All of the results are aggregated in the resulting JSAPResult.
Default behavior is to disallow multiple declarations.
- Parameters:
allowMultipleDeclarations
- if true, multiple declarations are allowed.- Returns:
- the modified FlaggedOption
-
allowMultipleDeclarations
public boolean allowMultipleDeclarations()
Returns a boolean indicating whether multiple declarations are allowed for this FlaggedOption.- Returns:
- a boolean indicating whether multiple declarations are allowed for this FlaggedOption.
- See Also:
setAllowMultipleDeclarations(boolean)
-
getSyntax
public java.lang.String getSyntax()
Returns syntax instructions for this FlaggedOption.
-
setList
public FlaggedOption setList(boolean isList)
Sets whether this FlaggedOption is a list. Default behavior is JSAP.NOT_LIST.- Parameters:
isList
- if true, this Option is a list.- Returns:
- the modified FlaggedOption
-
setListSeparator
public FlaggedOption setListSeparator(char listSeparator)
Sets the list separator character for this FlaggedOption. The default list separator is JSAP.DEFAULT_LISTSEPARATOR.- Parameters:
listSeparator
- the list separator for this Option.- Returns:
- the modified FlaggedOption
-
setRequired
public FlaggedOption setRequired(boolean required)
Sets whether this FlaggedOption is required. Default is JSAP.NOT_REQUIRED.- Parameters:
required
- if true, this Option will be required.- Returns:
- the modified FlaggedOption
-
setDefault
public FlaggedOption 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)
-
setDefault
public FlaggedOption 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)
-
setStringParser
public FlaggedOption setStringParser(StringParser stringParser)
Sets the StringParser to which this FlaggedOption's parse() method should delegate.- Parameters:
stringParser
- the StringParser to which this Option's parse() method should delegate.- Returns:
- the modified FlaggedOption
- See Also:
StringParser
-
-