public class CArguments extends Object
public class Jar implements ArgumentsHandler {
public static void main(final String [] args) {
Jar jar = new Jar();
CArguments arguments = new CArguments(jar,
new String [] {"c", "t", "x", "u" "v", "0", "M"},
new String [] {"f", "m", "C"});
arguments.processArguments(args);
}
public void option(final String name, final String argument) {
// Handle flags and options here...
}
public void programArguments(final String [] arguments) {
// Handle program arguments (files) here...
}
}
The Jar class can now be called like this:ArgumentsHandler| Constructor and Description |
|---|
CArguments(ArgumentsHandler argumentsHandler,
String[] flags,
String[] options)
Creates an arguments object from the supplied arguments handler, flags and options.
|
CArguments(ArgumentsHandler argumentsHandler,
String[] flags,
String[] options,
boolean allowUnspecifiedOptions)
Creates an arguments object from the supplied arguments handler, flags and options.
|
| Modifier and Type | Method and Description |
|---|---|
void |
parseArguments(String[] arguments)
Parses the actual arguments that have been supplied to a program.
|
String |
toString()
Creates a String representation of this object.
|
public CArguments(ArgumentsHandler argumentsHandler, String[] flags, String[] options)
argumentsHandler - Object that will receive callbacks for all flags, options and program arguments that are
encountered.flags - All allowable flags.
options - All allowable options.
IllegalArgumentException - When duplicate flags are supplied or when duplicate options are supplied or when a flag
and an option with the same name have been supplied.NullPointerException - When the supplied argumentsHandler is null.public CArguments(ArgumentsHandler argumentsHandler, String[] flags, String[] options, boolean allowUnspecifiedOptions)
argumentsHandler - Object that will receive callbacks for all flags, options and program arguments that are
encountered.flags - All allowable flags.
options - All allowable options.
allowUnspecifiedOptions - When the actual command line arguments contain an option that has not been specified in
the supplied options array then this option is handled gracefully when true is specified.NullPointerException - When the supplied argumentsHandler is null.IllegalArgumentException - When duplicate flags are supplied or when duplicate options are supplied or when a flag
and an option with the same name have been supplied.public void parseArguments(String[] arguments)
ArgumentsHandler.option(String, String) will be called. Even in the absence of program arguments will the method
ArgumentsHandler.programArguments(String[]) be called.arguments - Arguments supplied to the program.
IllegalArgumentException - When the actual arguments do not comply with the allowed flags and options.Copyright © 2008–2017. All rights reserved.