|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.eigenbase.util.OptionsList.Option
public abstract static class 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 | |
---|---|
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 OptionsList.OptionHandler
, or overridden the set
method, this field
is not assigned.
Several derived classes have typesafe methods to access this
field: see OptionsList.BooleanOption.booleanValue()
, OptionsList.StringOption.stringValue()
, OptionsList.NumberOption.intValue()
, OptionsList.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 an OptionsList.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(org.eigenbase.util.OptionsList.Option, java.lang.Object, boolean)
or OptionsList.OptionHandler.invalidValue(org.eigenbase.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(org.eigenbase.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 |