|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.brains2b.console.ArgumentMap
An ArgumentMap is a 'road map' to the arguments that can be supplied to Main and the expected follow up.
arguments and options are read in the order they where supplied in by static void main(String[] args)
The arguments and their key are stored in a HashMap fur future retrieval.
You can either add options, which could be translated as switches or add arguments
where the entire argument which is supplied by static void main(String[] args)
is
supplied to Main.
You can add options to an argument. Which means that the value of an argument will have to be one of the options, otherwise the argument will be ignored if it is optional or throw an ArgumentException if it is not optional.
You can add an argument to an option. Which means that main after finding the option looks for an argument belonging to it. This argument has its own name and can be later referenced by this name.
Options can have next to the required long form, an alternative optional one character short form. supplying options to Java will either be --longform or -shortform in good Unix fashion. Both forms will signify the same option.
Constructor Summary | |
ArgumentMap()
Constructor for ArgumentMap. |
Method Summary | |
void |
addArgument(java.lang.String name,
boolean required)
adds an Argument to the root of this map. |
void |
addArgument(java.lang.String name,
java.lang.String defaultValue)
adds an Argument to the root of this map. |
void |
addArgumentTo(java.lang.String option,
java.lang.String name,
boolean required)
Adds an argument to an option |
void |
addOption(java.lang.String longKey,
char shortKey,
boolean required)
adds an Option to the root of this map. |
void |
addOptionTo(java.lang.String argument,
java.lang.String longKey,
char shortKey)
adds an option to an argument |
java.util.Map |
getList(java.lang.String[] args)
gets the Map of all arguments supplied through String[] args mapped to their argument name. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public ArgumentMap()
Method Detail |
public void addArgument(java.lang.String name, boolean required)
A root can have multiple arguments and options
name
- String, the name for this argumentrequired
- boolean, is this argument requiredpublic void addArgument(java.lang.String name, java.lang.String defaultValue)
A root can have multiple arguments and options
name
- String, the name for this argumentdefaultValue
- String, value of this argument when non is supplied.public void addOption(java.lang.String longKey, char shortKey, boolean required)
A root can have multiple arguments and options
longKey
- String , the long form of the name, used as argument name, must be uniqueshortKey
- char, the one character short key, must be uniquerequired
- boolean, is the option required.public void addArgumentTo(java.lang.String option, java.lang.String name, boolean required)
This will typically take the form of -o argument
or --option argument
option
- String, the option to add the argument to.name
- String, the name of the argument.required
- boolean, is the argument required, if the option is supplied. If the option
is optional leaving the option out will not check for the required argument. However if the option
is supplied it must be followed by a value for this argument.public void addOptionTo(java.lang.String argument, java.lang.String longKey, char shortKey)
This means that if we defined an argument argument
and added options one, two, three
to it, finding any of these
options will be set as value for argument. If the argument is required and none
of the defined options is supplied an ArgumentException is thrown when processing
the input.
argument
- longKey
- shortKey
- public java.util.Map getList(java.lang.String[] args) throws ArgumentException
args
- String[], the array of arguments typically supplied from static void main(String[] args)
ArgumentException,
- ArgumentException is thrown when a required argument is missing either in the
root or from an option, or when a non-defined argument or option is found when not in the root.
ArgumentException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |