com.martiansoftware.jsap
Class FlaggedOption

java.lang.Object
  extended bycom.martiansoftware.jsap.Parameter
      extended bycom.martiansoftware.jsap.Option
          extended bycom.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
FlaggedOption(String id)
          Creates a new FlaggedOption with the specified unique ID.
FlaggedOption(String id, StringParser stringParser, String defaultValue, boolean required, char shortFlag, String longFlag)
          A shortcut constructor that creates a new FlaggedOption and configures its most commonly used settings.
FlaggedOption(String id, StringParser stringParser, String defaultValue, boolean required, char shortFlag, String longFlag, String help)
          A shortcut constructor that creates a new FlaggedOption and configures its most commonly used settings, including help.
 
Method Summary
 boolean allowMultipleDeclarations()
          Returns a boolean indicating whether multiple declarations are allowed for this FlaggedOption.
 String getLongFlag()
          Returns the long flag for this FlaggedOption.
 char getShortFlag()
          Returns the short flag for this FlaggedOption.
 Character getShortFlagCharacter()
          Returns the short flag for this FlaggedOption.
 String getSyntax()
          Returns syntax instructions for this FlaggedOption.
 FlaggedOption setAllowMultipleDeclarations(boolean allowMultipleDeclarations)
          Sets this FlaggedOption to allow or disallow multiple declarations.
 FlaggedOption setDefault(String defaultValue)
          Sets a default value for this parameter.
 FlaggedOption setDefault(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(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(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
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FlaggedOption

public FlaggedOption(String id)
Creates a new FlaggedOption with the specified unique ID.

Parameters:
id - the unique ID for this FlaggedOption.

FlaggedOption

public FlaggedOption(String id,
                     StringParser stringParser,
                     String defaultValue,
                     boolean required,
                     char shortFlag,
                     String longFlag,
                     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 to JSAP.NO_HELP for none).

FlaggedOption

public FlaggedOption(String id,
                     StringParser stringParser,
                     String defaultValue,
                     boolean required,
                     char shortFlag,
                     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 interface Flagged
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 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 interface Flagged
Returns:
the short flag for this FlaggedOption. If this FlaggedOption has no short flag, the return value will be null.

setLongFlag

public FlaggedOption setLongFlag(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(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 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 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.

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 String getSyntax()
Returns syntax instructions for this FlaggedOption.

Specified by:
getSyntax in class Parameter
Returns:
syntax instructions for this FlaggedOption based upon its current configuration.

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(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(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


Copyright © 2002-2006, Martian Software, Inc.. All Rights Reserved.
For the latest version and documentation, please visit http://www.martiansoftware.com/jsap