|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.commons.cli.Option
public class Option
Describes a single command-line option. It maintains information regarding the short-name of the option, the long-name, if any exists, a flag indicating if an argument is required for this option, and a self-documenting description of the option.
An Option is not created independantly, but is create through
an instance of Options
.
Options
,
CommandLine
,
Serialized FormField Summary | |
---|---|
private java.lang.String |
argName
the name of the argument for this option |
private java.lang.String |
description
description of the option |
private java.lang.String |
longOpt
the long representation of the option |
private int |
numberOfArgs
the number of argument values this option can have |
private java.lang.String |
opt
the name of the option |
private boolean |
optionalArg
specifies whether the argument value of this Option is optional |
private boolean |
required
specifies whether this option is required to be present |
private static long |
serialVersionUID
|
private java.lang.Object |
type
the type of this Option |
static int |
UNINITIALIZED
constant that specifies the number of argument values has not been specified |
static int |
UNLIMITED_VALUES
constant that specifies the number of argument values is infinite |
private java.util.List |
values
the list of argument values |
private char |
valuesep
the character that is the value separator |
Constructor Summary | |
---|---|
Option(java.lang.String opt,
boolean hasArg,
java.lang.String description)
Creates an Option using the specified parameters. |
|
Option(java.lang.String opt,
java.lang.String description)
Creates an Option using the specified parameters. |
|
Option(java.lang.String opt,
java.lang.String longOpt,
boolean hasArg,
java.lang.String description)
Creates an Option using the specified parameters. |
Method Summary | |
---|---|
private void |
add(java.lang.String value)
Add the value to this Option. |
boolean |
addValue(java.lang.String value)
Deprecated. |
(package private) void |
addValueForProcessing(java.lang.String value)
Adds the specified value to this Option. |
(package private) void |
clearValues()
Clear the Option values. |
java.lang.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. |
boolean |
equals(java.lang.Object o)
|
java.lang.String |
getArgName()
Gets the display name for the argument value. |
int |
getArgs()
Returns the number of argument values this Option can take. |
java.lang.String |
getDescription()
Retrieve the self-documenting description of this Option |
int |
getId()
Returns the id of this Option. |
(package private) java.lang.String |
getKey()
Returns the 'unique' Option identifier. |
java.lang.String |
getLongOpt()
Retrieve the long name of this Option. |
java.lang.String |
getOpt()
Retrieve the name of this Option. |
java.lang.Object |
getType()
Retrieve the type of this Option. |
java.lang.String |
getValue()
Returns the specified value of this Option or null if there is no value. |
java.lang.String |
getValue(int index)
Returns the specified value of this Option or null if there is no value. |
java.lang.String |
getValue(java.lang.String defaultValue)
Returns the value/first value of this Option or the defaultValue if there is no value. |
java.lang.String[] |
getValues()
Return the values of this Option as a String array or null if there are no values |
char |
getValueSeparator()
Returns the value separator character. |
java.util.List |
getValuesList()
|
boolean |
hasArg()
Query to see if this Option requires an argument |
boolean |
hasArgName()
Returns whether the display name for the argument value has been set. |
boolean |
hasArgs()
Query to see if this Option can take many values. |
int |
hashCode()
|
boolean |
hasLongOpt()
Query to see if this Option has a long name |
private boolean |
hasNoValues()
Returns whether this Option has any values. |
boolean |
hasOptionalArg()
|
boolean |
hasValueSeparator()
Return whether this Option has specified a value separator. |
boolean |
isRequired()
Query to see if this Option requires an argument |
private void |
processValue(java.lang.String value)
Processes the value. |
void |
setArgName(java.lang.String argName)
Sets the display name for the argument value. |
void |
setArgs(int num)
Sets the number of argument values this Option can take. |
void |
setDescription(java.lang.String description)
Sets the self-documenting description of this Option |
void |
setLongOpt(java.lang.String longOpt)
Sets the long name of this Option. |
void |
setOptionalArg(boolean optionalArg)
Sets whether this Option can have an optional argument. |
void |
setRequired(boolean required)
Sets whether this Option is mandatory. |
void |
setType(java.lang.Object type)
Sets the type of this Option. |
void |
setValueSeparator(char sep)
Sets the value separator. |
java.lang.String |
toString()
Dump state, suitable for debugging. |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private static final long serialVersionUID
public static final int UNINITIALIZED
public static final int UNLIMITED_VALUES
private java.lang.String opt
private java.lang.String longOpt
private java.lang.String argName
private java.lang.String description
private boolean required
private boolean optionalArg
private int numberOfArgs
private java.lang.Object type
private java.util.List values
private char valuesep
Constructor Detail |
---|
public Option(java.lang.String opt, java.lang.String description) throws java.lang.IllegalArgumentException
opt
- short representation of the optiondescription
- describes the function of the option
java.lang.IllegalArgumentException
- if there are any non valid
Option characters in opt
.public Option(java.lang.String opt, boolean hasArg, java.lang.String description) throws java.lang.IllegalArgumentException
opt
- short representation of the optionhasArg
- specifies whether the Option takes an argument or notdescription
- describes the function of the option
java.lang.IllegalArgumentException
- if there are any non valid
Option characters in opt
.public Option(java.lang.String opt, java.lang.String longOpt, boolean hasArg, java.lang.String description) throws java.lang.IllegalArgumentException
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
java.lang.IllegalArgumentException
- if there are any non valid
Option characters in opt
.Method Detail |
---|
public int getId()
java.lang.String getKey()
public java.lang.String getOpt()
CommandLine.hasOption(String opt)
and
CommandLine.getOptionValue(String opt)
to check
for existence and argument.
public java.lang.Object getType()
public void setType(java.lang.Object type)
type
- the type of this Optionpublic java.lang.String getLongOpt()
public void setLongOpt(java.lang.String longOpt)
longOpt
- the long name of this Optionpublic void setOptionalArg(boolean optionalArg)
optionalArg
- specifies whether the Option can have
an optional argument.public boolean hasOptionalArg()
public boolean hasLongOpt()
public boolean hasArg()
public java.lang.String getDescription()
public void setDescription(java.lang.String description)
description
- The description of this optionpublic boolean isRequired()
public void setRequired(boolean required)
required
- specifies whether this Option is mandatorypublic void setArgName(java.lang.String argName)
argName
- the display name for the argument value.public java.lang.String getArgName()
public boolean hasArgName()
public boolean hasArgs()
public void setArgs(int num)
num
- the number of argument valuespublic void setValueSeparator(char sep)
sep
- The value separator.public char getValueSeparator()
public boolean hasValueSeparator()
public int getArgs()
void addValueForProcessing(java.lang.String value)
value
- is a/the value of this Optionprivate void processValue(java.lang.String value)
value
- The String to be processed.private void add(java.lang.String value)
value
- The value to be added to this Optionpublic java.lang.String getValue()
null
if there is no value.
null
if there is no value.public java.lang.String getValue(int index) throws java.lang.IndexOutOfBoundsException
null
if there is no value.
index
- The index of the value to be returned.
null
if there is no value.
java.lang.IndexOutOfBoundsException
- if index is less than 1
or greater than the number of the values for this Option.public java.lang.String getValue(java.lang.String defaultValue)
defaultValue
if there is no value.
defaultValue
- The value to be returned if ther
is no value.
defaultValue
if there are no values.public java.lang.String[] getValues()
public java.util.List getValuesList()
public java.lang.String toString()
toString
in class java.lang.Object
private boolean hasNoValues()
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.Object clone()
clone
in class java.lang.Object
java.lang.RuntimeException
void clearValues()
public boolean addValue(java.lang.String value)
java.lang.UnsupportedOperationException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |