public abstract class Parameter extends Object
Top-level abstraction of a parameter. A parameter consists of one or more arguments (command line tokens) that have a special meaning when taken together. For example, a command-line switch "-v" is a parameter consisting of a single argument, whereas a command-line option "--file somefile.txt" is a parameter consisting of two arguments. Some parameters can be quite large, such as an option for a file compression utility that allows you to specify any number of files to comporess.
This is an abstract class. See its subclasses Switch
,
FlaggedOption
, and UnflaggedOption
for details on the various types of parameters. Functionality common to all three
types of Parameters is described below.
Each parameter has a unique ID assigned in its constructor. This ID is
used to retrieve values from the parser after the command line is parsed.
You can set the ID to any String value you wish, although in general you'll
want them to be brief and descriptive to provide a degree of documentation.
A "-h" switch, for example, might have the ID "help".
The calling program can then determine if the user specified the -h switch on
the command line with the simple call getBoolean("help")
against
the JSAPResult object produced by JSAP.parse().
Switch
,
FlaggedOption
,
UnflaggedOption
,
JSAPResult.getBoolean(String)
,
JSAP.parse(String[])
Constructor and Description |
---|
Parameter(String id)
Creates a new Parameter.
|
Modifier and Type | Method and Description |
---|---|
protected void |
_setDefault(String defaultValue)
Sets a default value for this parameter.
|
protected void |
_setDefault(String[] defaultValues)
Sets one or more default values for this parameter.
|
protected void |
_setUsageName(String usageName)
Sets the name of this AbstractParameter for the purposes of
usage information.
|
void |
addDefault(String defaultValue)
Adds a single default value to any currently defined for this
parameter.
|
protected void |
enforceParameterLock()
Helper method that can be called by any methods that modify this
parameter (or its subclasses).
|
String[] |
getDefault()
Returns an array of default values for this parameter, or
null if no default values have been defined.
|
String |
getHelp()
Returns a description of the option's usage.
|
String |
getID()
Returns this parameter's unique ID.
|
abstract String |
getSyntax()
A convenience method for automatically generating syntax
information based upon a JSAP configuration.
|
String |
getUsage()
Deprecated.
use getSyntax() instead
|
String |
getUsageName()
Returns the name of this AbstractParameter for the purposes of
usage information.
|
protected boolean |
locked()
Returns a boolean indicating whether this parameter is locked.
|
protected abstract List |
parse(String arg)
Returns an ArrayList of values resulting from the parsing
of the specified argument.
|
Parameter |
setHelp(String help)
Sets the help text for this parameter.
|
protected void |
setLocked(boolean locked)
Locks or unlocks this parameter.
|
public Parameter(String id)
id
- The ID for this argument. All arguments MUST have
a unique ID.public String getID()
protected final void setLocked(boolean locked)
locked
- if TRUE
, locks this parameter. if
FALSE
, unlocks it.JSAP.registerParameter(Parameter)
protected final boolean locked()
protected final void enforceParameterLock()
protected final void _setDefault(String defaultValue)
defaultValue
- the default value for this parameter.protected final void _setDefault(String[] defaultValues)
defaultValues
- the default values for this parameter.public final void addDefault(String defaultValue)
defaultValue
- the default value to add to this parameter.protected final void _setUsageName(String usageName)
usageName
- the usage name for this AbstractParameterpublic final String getUsageName()
public final String[] getDefault()
protected abstract List parse(String arg) throws ParseException
arg
- the argument to parse.ParseException
- if the specified argument cannot be parsed.public abstract String getSyntax()
public final String getUsage()
public final String getHelp()
Copyright © 2016. All rights reserved.