public class Main
extends java.lang.Object
The way to use this class is to extend your own class that contains a main method.
public class AConsole {
public AConsole() {
super();
init();
//other code
}
public static void main (String[] args) {
AConsole a=new AConsole();
a.makeArguments(args);
a.start();
}
private void init() {
ArgumentMap arg=new ArgumentMap();
//add arguments
setArgumentMap(arg);
}
private void start() {
//do your thing
}
}
ArgumentMap| Constructor and Description |
|---|
Main()
Constructor for Main.
|
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
getArgument(java.lang.String name)
gets the value of an argument defined by name.
|
protected ArgumentMap |
getArgumentMap()
gets the ArgumentMap.
|
protected void |
handleException(ArgumentException ex)
Default function for handling ArgumentException(s).
|
void |
makeArgumentList(java.lang.String[] args)
Makes the argument list on the basis of a defined ArgumentMap and the supplied
array of arguments
|
void |
setArgument(java.lang.String name,
java.lang.String value)
set arguments to the list of arguments.
|
protected void |
setArgumentMap(ArgumentMap argumentMap)
Sets the ArgumentMap.
|
protected ArgumentMap getArgumentMap()
protected void setArgumentMap(ArgumentMap argumentMap)
argumentMap - ArgumentMap, the created ArgumentMappublic java.lang.String getArgument(java.lang.String name)
java.lang.NullPointerException - thrown if there was no argument list made (forgot to call makeArgumentList()?)public void setArgument(java.lang.String name,
java.lang.String value)
This method does not check for validity of the argument and can possibly overwrite arguments set with makeArgumentList. Checking your arguments should be done by your own code.
name - value - public void makeArgumentList(java.lang.String[] args)
If an ArgumentMap exists the arguments are passed to ArgumentMap.getList(String[])
If no ArgumentMap exists a List is made with the numeric location of the argument as name and the corresponding value of the Array as value.
args - String[] An array of argumentsArgumentMap.getList(java.lang.String[])protected void handleException(ArgumentException ex)
It writes the argument that caused the exception and the exception message to the System.err outstream and exits the VM with code 1.
Overwrite if you want it to do something else.
Be sure to break normal operation if not exiting while arguments and options
you set to required are not actually there and you have not set default values.
ex - ArgumentException