|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object marf.util.OptionProcessor
public class OptionProcessor
Command-Line Option Processing Facilitating Utility. Helps to maintain and validate command-line options and their arguments. The class is properly synchronized as of 0.3.0.4.
$Id: OptionProcessor.java,v 1.38 2007/12/23 06:29:47 mokhov Exp $
Nested Class Summary | |
---|---|
protected class |
OptionProcessor.Option
Main Option placeholder. |
protected class |
OptionProcessor.OptionsHashtable
A hashtable designed for to hold options. |
Field Summary | |
---|---|
protected java.util.Hashtable |
oActiveOptionsNumbers
A hash-table that contains active numerical options amp. |
protected java.util.Hashtable |
oActiveOptionsStrings
A hash-table that contains active string options map. |
protected java.util.Vector |
oInvalidOptions
A vector that contains invalid options for error reporting. |
protected java.util.Hashtable |
oValidOptionsNumbers
A hash-table that contains valid numerical options map. |
protected java.util.Hashtable |
oValidOptionsStrings
A hash-table that contains valid string options map. |
static int |
UNDEF
Indicates undefined option (-1). |
Constructor Summary | |
---|---|
OptionProcessor()
Constructs options-free OptionProcessor. |
|
OptionProcessor(java.util.Hashtable poValidOptions)
Constructs OptionProcessor with known list of
options from a Hashtable by converting its
contents to internal data structures. |
Method Summary | |
---|---|
void |
addActiveOption(int piOptionCode,
java.lang.String pstrOptionString)
Allows adding an active option to the set of active options directly. |
protected void |
addActiveOption(OptionProcessor.Option poOption)
Adds active option. |
void |
addActiveOption(java.lang.String pstrOptionString)
Allows adding a value option. |
void |
addActiveOption(java.lang.String pstrOptionString,
java.lang.String pstrOptionValue)
Allows adding a valid option to the set of valid options. |
void |
addValidOption(int piOptionCode,
java.lang.String pstrOptionString)
Allows adding a valid option to the set of valid options. |
void |
addValidOption(int piOptionCode,
java.lang.String pstrOptionString,
boolean pbRequiresArgument)
Allows adding a valid option to the set of valid options indicating the necessity of argument to it. |
protected void |
addValidOption(OptionProcessor.Option poOption)
Adds valid option. |
void |
addValidOption(java.lang.String pstrOptionString)
Allows adding a value option. |
void |
clear()
Clears out all the option lists of this option processor. |
java.util.Hashtable |
getActiveOptions()
Allows querying for the set of active options. |
java.lang.String |
getArgumentString()
Returns active and invalid options (in that order) in a form suitable to feed back as an argument string to an external application. |
java.lang.String[] |
getArgumentVector()
Returns active and invalid options (in that order) in a form suitable to feed back as an argument vector argv
to another application's main() . |
java.util.Vector |
getInvalidOptions()
Allows querying for the set of invalid options. |
static java.lang.String |
getMARFSourceCodeRevision()
Retrieves class' revision. |
java.lang.String |
getOption(int piOption)
Returns string equivalent of a numerical option. |
java.lang.String |
getOption(int piOption,
boolean pbReturnOnError)
Returns string equivalent of a numerical option. |
int |
getOption(java.lang.String pstrOption)
Returns numerical equivalent of an option string. |
int |
getOption(java.lang.String pstrOption,
boolean pbReturnOnError)
Returns numerical equivalent of an option string. |
java.lang.String |
getOptionArgument(int piOption)
Allows querying for option argument by option number. |
java.lang.String |
getOptionArgument(int piOption,
boolean pbReturnOnError)
Allows querying for option argument by option number. |
java.lang.String |
getOptionArgument(java.lang.String pstrOption)
Allows querying for option argument by option name. |
java.lang.String |
getOptionArgument(java.lang.String pstrOption,
boolean pbReturnOnError)
Allows querying for option argument by option name. |
java.util.Hashtable |
getValidOptions()
Allows querying for the set of active options. |
boolean |
isActiveOption(int piOption)
Checks whether supplied integer option is active. |
boolean |
isActiveOption(java.lang.String pstrOption)
Checks whether supplied string option is active. |
boolean |
isInvalidOption(java.lang.String pstrOption)
Checks whether supplied string option is invalid. |
boolean |
isValidOption(int piOption)
Checks whether supplied integer option is valid. |
boolean |
isValidOption(java.lang.String pstrOption)
Checks whether supplied string option is valid. |
int |
parse(java.lang.String[] argv)
Parses option strings from the argument vector. |
int |
size()
Retrieves the option count currently known to the option processor as a sum of active and invalid options. |
java.lang.String |
toString()
Converts the internals of the OptionProcessor to a string and returns it. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int UNDEF
protected java.util.Hashtable oValidOptionsStrings
protected java.util.Hashtable oValidOptionsNumbers
protected java.util.Hashtable oActiveOptionsStrings
protected java.util.Hashtable oActiveOptionsNumbers
protected java.util.Vector oInvalidOptions
Constructor Detail |
---|
public OptionProcessor()
public OptionProcessor(java.util.Hashtable poValidOptions)
OptionProcessor
with known list of
options from a Hashtable
by converting its
contents to internal data structures.
This expects the Hashtable
to contain
String
:Integer
pairs;
the pairs that do not conform to this requirement are added to
the invalid options collection.
poValidOptions
- a collection of valid options; if null then
the internal hashtable remains empty and is not set to null.Method Detail |
---|
public void addActiveOption(java.lang.String pstrOptionString, java.lang.String pstrOptionValue)
addActiveOption
in interface IOptionProvider
pstrOptionString
- option's namepstrOptionValue
- option's valuepublic final void addValidOption(int piOptionCode, java.lang.String pstrOptionString)
addValidOption
in interface IOptionProvider
piOptionCode
- option's numerical code to use, a valuepstrOptionString
- option's lexical representation, a keypublic final void addValidOption(java.lang.String pstrOptionString)
addValidOption
in interface IOptionProvider
pstrOptionString
- option's lexical representation, a keyIOptionProvider.addValidOption(java.lang.String)
public final void addValidOption(int piOptionCode, java.lang.String pstrOptionString, boolean pbRequiresArgument)
addValidOption
in interface IOptionProvider
piOptionCode
- option's numerical code to use, a valuepstrOptionString
- option's lexical representation, a keypbRequiresArgument
- set to true
if the option
requires argument. An exception will be thrown during parsing
if an option that requires an argument doesn't get one.parse(String[])
protected final void addValidOption(OptionProcessor.Option poOption)
poOption
- option object to add to valid optionspublic final void addActiveOption(int piOptionCode, java.lang.String pstrOptionString)
addActiveOption
in interface IOptionProvider
piOptionCode
- option's numerical code to use, a valuepstrOptionString
- option's lexical representation, a keyprotected final void addActiveOption(OptionProcessor.Option poOption)
poOption
- option object to add to active optionspublic final void addActiveOption(java.lang.String pstrOptionString)
addActiveOption
in interface IOptionProvider
pstrOptionString
- option's lexical representation, a keyIOptionProvider.addValidOption(java.lang.String)
public void clear()
public int size()
size
in interface IOptionProvider
public java.lang.String[] getArgumentVector()
argv
to another application's main()
. Essentially,
this allows reconstruct the original argv
except
that the only ordering guaranteed is that all active are
followed by all invalid options.
getArgumentVector
in interface IOptionProvider
public java.lang.String getArgumentString()
getArgumentString
in interface IOptionProvider
public final int parse(java.lang.String[] argv)
Parses option strings from the argument vector. Does not alter the argument vector itself, but initializes internal active and invalid options. If the same options occurs more than once, the last occurrence only takes effect.
NOTICE, since 0.3.0.3 '=' has a special meaning as a separator between options and values, and, therefore, cannot appear inside option strings or by itself on the command line.
argv
- argument vector (array of command-line options)
java.lang.RuntimeException
- if some valid option that requires an argument
doesn't have one.public final int getOption(java.lang.String pstrOption)
getOption
in interface IOptionProvider
pstrOption
- option string to look the integer equivalent for
java.lang.RuntimeException
- if the named option is not found to be active/validpublic final int getOption(java.lang.String pstrOption, boolean pbReturnOnError)
getOption
in interface IOptionProvider
pstrOption
- option string to look the integer equivalent forpbReturnOnError
- tells getOption to return UNDEF instead of throwing an
exception if set to true>
- Returns:
- int, the option enumeration value
- Throws:
java.lang.RuntimeException
- if the named option is not found to be active/valid
public final java.lang.String getOption(int piOption)
getOption
in interface IOptionProvider
piOption
- option to look the String equivalent for
java.lang.RuntimeException
- if the named option is not found to be active/validpublic final java.lang.String getOption(int piOption, boolean pbReturnOnError)
getOption
in interface IOptionProvider
piOption
- option to look the String equivalent forpbReturnOnError
- tells getOption to return an empty string instead of throwing an
exception if set to true>
- Returns:
- the option string
- Throws:
java.lang.RuntimeException
- if the named option is not found to be active/valid
public java.lang.String getOptionArgument(java.lang.String pstrOption)
getOptionArgument
in interface IOptionProvider
pstrOption
- option name
public java.lang.String getOptionArgument(java.lang.String pstrOption, boolean pbReturnOnError)
getOptionArgument
in interface IOptionProvider
pstrOption
- option namepbReturnOnError
- tells to return an empty string instead of throwing an
exception if set to true>
- Returns:
- option argument
- Since:
- 0.3.0.3
public java.lang.String getOptionArgument(int piOption)
getOptionArgument
in interface IOptionProvider
piOption
- option number
public java.lang.String getOptionArgument(int piOption, boolean pbReturnOnError)
getOptionArgument
in interface IOptionProvider
piOption
- option numberpbReturnOnError
- tells to return an empty string instead of throwing an
exception if set to true>
- Returns:
- option argument
- Since:
- 0.3.0.3
public final java.util.Vector getInvalidOptions()
getInvalidOptions
in interface IOptionProvider
public final java.util.Hashtable getActiveOptions()
getActiveOptions
in interface IOptionProvider
public final java.util.Hashtable getValidOptions()
getValidOptions
in interface IOptionProvider
public boolean isActiveOption(java.lang.String pstrOption)
isActiveOption
in interface IOptionProvider
pstrOption
- option to verify
true
if the option is active, false
otherwisepublic boolean isActiveOption(int piOption)
isActiveOption
in interface IOptionProvider
piOption
- option to verify
true
if the option is active, false
otherwisepublic boolean isValidOption(java.lang.String pstrOption)
isValidOption
in interface IOptionProvider
pstrOption
- option to verify
true
if the option is valid, false
otherwisepublic boolean isValidOption(int piOption)
isValidOption
in interface IOptionProvider
piOption
- option to verify
true
if the option is active, false
otherwisepublic boolean isInvalidOption(java.lang.String pstrOption)
isInvalidOption
in interface IOptionProvider
pstrOption
- option to verify
true
if the option is invalid, false
otherwisepublic java.lang.String toString()
toString
in class java.lang.Object
public static java.lang.String getMARFSourceCodeRevision()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |