|
MOEA Framework 2.5 API Specification |
|||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||
java.lang.Objectorg.moeaframework.util.CommandLineUtility
public abstract class CommandLineUtility
Abstract class for providing command line utilities. This class is provided to ensure a standard interface for command line utilities as well as handling the quirks of different operating systems.
Upon calling start(String[]), this class registers an uncaught
exception handler on the calling thread. The purpose of this handler is to
catch any exceptions and display a formatted error message on the command
line.
As such, subclasses should include a main method similar to the following:
public class MyCustomUtility extends CommandLineUtility {
// implement the run and getOptions methods
public static void main(String[] args) throws Exception {
new MyCustomUtility().start(args);
}
}
Note that the main method always throws an Exception. This ensures
the error is propagated to the uncaught exception handler.
| Constructor Summary | |
|---|---|
CommandLineUtility()
Constructs a command line utility. |
|
| Method Summary | |
|---|---|
String |
getCommandString()
Returns the command string used to invoke this command line utility. |
org.apache.commons.cli.Options |
getOptions()
Returns the options made available by this command line utility. |
abstract void |
run(org.apache.commons.cli.CommandLine commandLine)
Runs this command line utility with the specified command line arguments. |
void |
setCommandString(String commandString)
Sets the command string used to invoke this command line utility. |
void |
start(String[] args)
Starts this command line utility with the command line arguments provided by the main method. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public CommandLineUtility()
| Method Detail |
|---|
public org.apache.commons.cli.Options getOptions()
-h,--help option.
Implementations overriding this method and begin with a call to
super.getOptions().
public abstract void run(org.apache.commons.cli.CommandLine commandLine)
throws Exception
commandLine - the command line arguments
Exception
public void start(String[] args)
throws Exception
main method. The command line arguments are
parsed into a CommandLine object and the run method is
invoked.
At the start of this method, a specialized uncaught exception handler is registered with the calling thread. This exception handler is responsible for formatting and displaying any errors on the command line. Note that this exception handler is not removed at the end of this method; its removal is not necessary when this utility is invoked on the command line.
args - the command line arguments
Exceptionpublic String getCommandString()
public void setCommandString(String commandString)
commandString - the command string used to invoke this command line
utility; or null to use the default Java command line
string
|
MOEA Framework 2.5 API Specification |
|||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||