Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
org.apache.commons.cli.Option
public class Option
extends java.lang.Object
implements Cloneable
Options
.
Options
, CommandLine
Field Summary | |
static int |
|
static int |
|
private String |
|
private String |
|
private boolean |
|
private String |
|
private int |
|
private String |
|
private boolean |
|
private boolean |
|
private Object |
|
private ArrayList |
|
private char |
|
Constructor Summary | |
| |
| |
|
Method Summary | |
private void |
|
boolean |
|
(package private) void |
|
(package private) void |
|
Object |
|
boolean |
|
String |
|
int |
|
String |
|
int |
|
(package private) String |
|
String |
|
String |
|
Object |
|
String |
|
String |
|
String |
|
char |
|
String[] |
|
java.util.List | |
boolean |
|
boolean |
|
boolean |
|
boolean |
|
private boolean |
|
boolean | |
boolean |
|
int |
|
boolean |
|
private void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
String |
|
public static final int UNINITIALIZED
constant that specifies the number of argument values has not been specified
- Field Value:
- -1
public static final int UNLIMITED_VALUES
constant that specifies the number of argument values is infinite
- Field Value:
- -2
private String argName
argName specifies the name of the argument for this option
private String description
description of the option
private boolean hasArg
hasArg specifies whether this option has an associated argument
private String longOpt
longOpt is the long representation of the option
private int numberOfArgs
numberOfArgs specifies the number of argument values this option can have
private String opt
opt the name of the option
private boolean optionalArg
specifies whether the argument value of this Option is optional
private boolean required
required specifies whether this option is required to be present
private Object type
the type of this Option
private ArrayList values
the list of argument values *
private char valuesep
the character that is the value separator
public Option(String opt, String description) throws IllegalArgumentException
Creates an Option using the specified parameters.
- Parameters:
opt
- short representation of the optiondescription
- describes the function of the option
public Option(String opt, String longOpt, boolean hasArg, String description) throws IllegalArgumentException
Creates an Option using the specified parameters.
- Parameters:
opt
- short representation of the optionlongOpt
- the long representation of the optionhasArg
- specifies whether the Option takes an argument or notdescription
- describes the function of the option
public Option(String opt, boolean hasArg, String description) throws IllegalArgumentException
Creates an Option using the specified parameters.
- Parameters:
opt
- short representation of the optionhasArg
- specifies whether the Option takes an argument or notdescription
- describes the function of the option
private void add(String value)
Add the value to this Option. If the number of arguments is greater than zero and there is enough space in the list then add the value. Otherwise, throw a runtime exception.
- Parameters:
value
- The value to be added to this Option
- Since:
- 1.0.1
public boolean addValue(String value)
Deprecated.
This method is not intended to be used. It was a piece of internal API that was made public in 1.0. It currently throws an UnsupportedOperationException.
(package private) void addValueForProcessing(String value)
Adds the specified value to this Option.
- Parameters:
value
- is a/the value of this Option
(package private) void clearValues()
Clear the Option values. After a parse is complete, these are left with data in them and they need clearing if another parse is done. See: CLI-71
public Object clone()
A rather odd clone method - due to incorrect code in 1.0 it is public and in 1.1 rather than throwing a CloneNotSupportedException it throws a RuntimeException so as to maintain backwards compat at the API level. After calling this method, it is very likely you will want to call clearValues().
public boolean equals(Object o)
public String getArgName()
Gets the display name for the argument value.
- Returns:
- the display name for the argument value.
public int getArgs()
Returns the number of argument values this Option can take.
- Returns:
- num the number of argument values
public String getDescription()
Retrieve the self-documenting description of this Option
- Returns:
- The string description of this option
public int getId()
Returns the id of this Option. This is only set when the Option shortOpt is a single character. This is used for switch statements.
- Returns:
- the id of this Option
(package private) String getKey()
Returns the 'unique' Option identifier.
- Returns:
- the 'unique' Option identifier
public String getLongOpt()
Retrieve the long name of this Option.
- Returns:
- Long name of this option, or null, if there is no long name
public String getOpt()
Retrieve the name of this Option. It is this String which can be used withCommandLine.hasOption(String opt)
andCommandLine.getOptionValue(String opt)
to check for existence and argument.
- Returns:
- The name of this option
public Object getType()
Retrieve the type of this Option.
- Returns:
- The type of this option
public String getValue()
Returns the specified value of this Option ornull
if there is no value.
- Returns:
- the value/first value of this Option or
null
if there is no value.
public String getValue(String defaultValue)
Returns the value/first value of this Option or thedefaultValue
if there is no value.
- Parameters:
defaultValue
- The value to be returned if ther is no value.
- Returns:
- the value/first value of this Option or the
defaultValue
if there are no values.
public String getValue(int index) throws IndexOutOfBoundsException
Returns the specified value of this Option ornull
if there is no value.
- Parameters:
index
- The index of the value to be returned.
- Returns:
- the specified value of this Option or
null
if there is no value.
public char getValueSeparator()
Returns the value separator character.
- Returns:
- the value separator character.
public String[] getValues()
Return the values of this Option as a String array or null if there are no values
- Returns:
- the values of this Option as a String array or null if there are no values
public java.util.List getValuesList()
- Returns:
- the values of this Option as a List or null if there are no values
public boolean hasArg()
Query to see if this Option requires an argument
- Returns:
- boolean flag indicating if an argument is required
public boolean hasArgName()
Returns whether the display name for the argument value has been set.
- Returns:
- if the display name for the argument value has been set.
public boolean hasArgs()
Query to see if this Option can take many values.
- Returns:
- boolean flag indicating if multiple values are allowed
public boolean hasLongOpt()
Query to see if this Option has a long name
- Returns:
- boolean flag indicating existence of a long name
private boolean hasNoValues()
Returns whether this Option has any values.
- Returns:
- whether this Option has any values.
public boolean hasOptionalArg()
- Returns:
- whether this Option can have an optional argument
public boolean hasValueSeparator()
Return whether this Option has specified a value separator.
- Returns:
- whether this Option has specified a value separator.
public int hashCode()
public boolean isRequired()
Query to see if this Option requires an argument
- Returns:
- boolean flag indicating if an argument is required
private void processValue(String value)
Processes the value. If this Option has a value separator the value will have to be parsed into individual tokens. When n-1 tokens have been processed and there are more value separators in the value, parsing is ceased and the remaining characters are added as a single token.
- Parameters:
value
- The String to be processed.
- Since:
- 1.0.1
public void setArgName(String argName)
Sets the display name for the argument value.
- Parameters:
argName
- the display name for the argument value.
public void setArgs(int num)
Sets the number of argument values this Option can take.
- Parameters:
num
- the number of argument values
public void setDescription(String description)
Sets the self-documenting description of this Option
- Parameters:
description
- The description of this option
public void setLongOpt(String longOpt)
Sets the long name of this Option.
- Parameters:
longOpt
- the long name of this Option
public void setOptionalArg(boolean optionalArg)
Sets whether this Option can have an optional argument.
- Parameters:
optionalArg
- specifies whether the Option can have an optional argument.
public void setRequired(boolean required)
Sets whether this Option is mandatory.
- Parameters:
required
- specifies whether this Option is mandatory
public void setType(Object type)
Sets the type of this Option.
- Parameters:
type
- the type of this Option
public void setValueSeparator(char sep)
Sets the value separator. For example if the argument value was a Java property, the value separator would be '='.
- Parameters:
sep
- The value separator.
public String toString()
Dump state, suitable for debugging.
- Returns:
- Stringified form of this object