Package com.martiansoftware.jsap
Class Option
- java.lang.Object
-
- com.martiansoftware.jsap.Parameter
-
- com.martiansoftware.jsap.Option
-
- Direct Known Subclasses:
FlaggedOption
,UnflaggedOption
public abstract class Option extends Parameter
The base class from which FlaggedOption and UnflaggedOption are derived. An Option is a Parameter that requires some information (unlike a Switch whose mere presence is significant).
Options may be declared as lists, or multiple values separated by a delimiting character. An example of a list option might be a classpath, which is a collection of paths separated by a ":" on *nix systems and a ";" on DOS/Windows systems. JSAP automatically separates list options into multiple tokens before calling their StringParsers' parse() method.The default list separator is JSAP.DEFAULT_LISTSEPARATOR, which is defined as the platform's path separator character (":" on *nix and ";" on DOS/Windows as described above).
- Author:
- Marty Lamb
- See Also:
Flagged
,Option
-
-
Constructor Summary
Constructors Constructor Description Option(java.lang.String id)
Creates a new Option with the specified unique ID.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description char
getListSeparator()
Returns the current list separator character for this Option.StringParser
getStringParser()
Returns the StringParser to which this Option will delegate calls to its parse() method, or null if no StringParser is currently defined.protected void
internalSetList(boolean isList)
Sets whether this Option is a list.protected void
internalSetListSeparator(char listSeparator)
Sets the list separator character for this Option.protected void
internalSetRequired(boolean required)
Sets whether this Option is required.protected void
internalSetStringParser(StringParser stringParser)
Sets the StringParser to which this Option's parse() method should delegate.boolean
isList()
Returns a boolean indicating whether this Option is a list.protected java.util.List
parse(java.lang.String arg)
Parses the specified argument, returning the results in an ArrayList.protected void
register()
Informs this Option's StringParser that this Option is being registered with a JSAP.boolean
required()
Returns a boolean indicating whether this Option is required.protected void
unregister()
Informs this Option's StringParser that this Option is being unregistered from a JSAP.-
Methods inherited from class com.martiansoftware.jsap.Parameter
_setDefault, _setDefault, _setUsageName, addDefault, enforceParameterLock, getDefault, getHelp, getID, getSyntax, getUsage, getUsageName, locked, setHelp, setLocked
-
-
-
-
Method Detail
-
internalSetList
protected final void internalSetList(boolean isList)
Sets whether this Option is a list. Default behavior is JSAP.NOT_LIST.- Parameters:
isList
- if true, this Option is a list.
-
isList
public final boolean isList()
Returns a boolean indicating whether this Option is a list.- Returns:
- a boolean indicating whether this Option is a list.
-
internalSetListSeparator
protected final void internalSetListSeparator(char listSeparator)
Sets the list separator character for this Option. The default list separator is JSAP.DEFAULT_LISTSEPARATOR.- Parameters:
listSeparator
- the list separator for this Option.
-
getListSeparator
public final char getListSeparator()
Returns the current list separator character for this Option.- Returns:
- the current list separator character for this Option.
-
internalSetRequired
protected final void internalSetRequired(boolean required)
Sets whether this Option is required. Default is JSAP.NOT_REQUIRED.- Parameters:
required
- if true, this Option will be required.
-
required
public final boolean required()
Returns a boolean indicating whether this Option is required.- Returns:
- a boolean indicating whether this Option is required.
-
internalSetStringParser
protected final void internalSetStringParser(StringParser stringParser)
Sets the StringParser to which this Option's parse() method should delegate.- Parameters:
stringParser
- the StringParser to which this Option's parse() method should delegate.- See Also:
StringParser
-
getStringParser
public final StringParser getStringParser()
Returns the StringParser to which this Option will delegate calls to its parse() method, or null if no StringParser is currently defined.- Returns:
- the StringParser to which this Option will delegate calls to its parse() method, or null if no StringParser is currently defined.
-
parse
protected final java.util.List parse(java.lang.String arg) throws ParseException
Parses the specified argument, returning the results in an ArrayList. List options are tokenized before the parse call is delegated to the StringParser.- Specified by:
parse
in classParameter
- Parameters:
arg
- the argument to parse.- Returns:
- a List of objects resulting from the parse.
- Throws:
ParseException
- if the specified argument (or one of its tokens, in the case of a list) cannot be parsed.
-
register
protected void register() throws JSAPException
Informs this Option's StringParser that this Option is being registered with a JSAP. If the StringParser requires any setup not taken care of in its constructor, it should override StringParser.setUp().- Throws:
JSAPException
- if the underlying StringParser throws it.- See Also:
StringParser.setUp()
-
unregister
protected void unregister()
Informs this Option's StringParser that this Option is being unregistered from a JSAP. If the StringParser requires any cleanup, it should ovverride StringParser.tearDown().- See Also:
StringParser.tearDown()
-
-