|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--net.sf.saffron.util.OptionsList.Option
Definition of a command-line option, including its short and long names, description, default value, and whether it is mandatory.
You can optionally provide a handler
to
handle events such as the option receiving a value, or a value being of
the wrong format. If you do not provide a handler, the value is stored
inside the option, and can be retrieved via
Field Summary | |
private Object |
defaultValue_
Default value of option, or null if there is no default value. |
private String |
description_
|
private String |
flag_
Short name of option, used as a flag, e.g. |
private OptionsList.OptionHandler |
handler_
|
private String |
name_
Long name of option, e.g. |
private boolean |
required_
|
protected Object |
value_
Holds the runtime value of this option. |
Constructor Summary | |
(package private) |
OptionsList.Option(String flag,
String option,
String description,
boolean required,
boolean anonymous,
Object defaultValue,
OptionsList.OptionHandler handler)
|
Method Summary | |
String |
getDescription()
|
String |
getName()
|
Object |
getValue()
Returns the value of this option for the most recent call to OptionsList.parse(java.lang.String[]) . |
int |
match(String[] args,
int i)
Tries to apply this option to the ith member of args. |
protected abstract void |
readArg(String arg)
Converts an argument to the correct value type, and acts on the value. |
void |
set(Object value,
boolean isExplicit)
|
void |
setHandler(OptionsList.OptionHandler handler)
|
protected void |
valueError(String arg)
Called by the parser when an argument is not a valid value for this type of argument. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected Object value_
set(java.lang.Object, boolean)
. If the user has supplied an OptionHandler
, or overridden the set
method, this
field is not assigned.
Several derived classes have typesafe methods to access this field:
see BooleanOption#booleanValue
, StringOption#stringValue
, NumberOption#intValue
, NumberOption#doubleValue
.
private final Object defaultValue_
private final String description_
private final String flag_
private final String name_
private final boolean required_
private OptionsList.OptionHandler handler_
Constructor Detail |
OptionsList.Option(String flag, String option, String description, boolean required, boolean anonymous, Object defaultValue, OptionsList.OptionHandler handler)
Method Detail |
public String getDescription()
public void setHandler(OptionsList.OptionHandler handler)
public String getName()
public Object getValue()
OptionsList.parse(java.lang.String[])
.
If you specified a OptionHandler
, this value will not be
set. Also note that this method is unsafe if the same options are
shared between multiple threads.
Some derived classes have methods which return the same information
in a typesafe manner. For example:
OptionsList.BooleanOption.booleanValue()
,
OptionsList.NumberOption.intValue()
.
public int match(String[] args, int i)
args
- Argument listi
- Offset of argument in argument list
public void set(Object value, boolean isExplicit)
protected abstract void readArg(String arg)
What action is taken depends upon whether the value is valid for
this argument type, and whether there is a handler. If there is a
handler, this method calls either
OptionsList.OptionHandler.set(net.sf.saffron.util.OptionsList.Option, java.lang.Object, boolean)
or
OptionsList.OptionHandler.invalidValue(net.sf.saffron.util.OptionsList.Option, java.lang.String)
. If there is no
handler, the method should execute a reasonable default action like
assigning to a field via reflection.
arg
- protected void valueError(String arg)
For example, if "flag" is a boolean argument and they specify
"flag=oui" on the command-line, the parser will call
valueError("oui")
.
The default implementation calls
OptionsList.OptionHandler.invalidValue(net.sf.saffron.util.OptionsList.Option, java.lang.String)
if there is a handler, or prints a message to System.out
if there is not. Derived option classes can override this method.
arg
- String value which is supposed to match the parameter,
but doesn't.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |