MOEA Framework 2.12
API Specification

org.moeaframework.util
Class CommandLineUtility

java.lang.Object
  extended by org.moeaframework.util.CommandLineUtility
Direct Known Subclasses:
AerovisConverter, Analysis, ARFFConverter, DetailedEvaluator, Evaluator, ExtractData, FileProtection, LaunchDiagnosticTool, Negater, ReferenceSetMerger, ResultFileEvaluator, ResultFileInfo, ResultFileMerger, ResultFileSeedMerger, SampleGenerator, SetContribution, SetGenerator, SetHypervolume, SimpleStatistics, SobolAnalysis, Solve

public abstract class CommandLineUtility
extends Object

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

CommandLineUtility

public CommandLineUtility()
Constructs a command line utility. The constructor for subclasses should provide a private constructor unless programmatic access is also desired.

Method Detail

getOptions

public org.apache.commons.cli.Options getOptions()
Returns the options made available by this command line utility. The base implementation automatically provides the -h,--help option. Implementations overriding this method and begin with a call to super.getOptions().

Returns:
the options made available by this command line utility

run

public abstract void run(org.apache.commons.cli.CommandLine commandLine)
                  throws Exception
Runs this command line utility with the specified command line arguments.

Parameters:
commandLine - the command line arguments
Throws:
Exception

start

public void start(String[] args)
           throws Exception
Starts this command line utility with the command line arguments provided by the 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.

Parameters:
args - the command line arguments
Throws:
Exception

getCommandString

public String getCommandString()
Returns the command string used to invoke this command line utility.

Returns:
the command string used to invoke this command line utility

setCommandString

public void setCommandString(String commandString)
Sets the command string used to invoke this command line utility.

Parameters:
commandString - the command string used to invoke this command line utility; or null to use the default Java command line string

MOEA Framework 2.12
API Specification

Copyright 2009-2016 MOEA Framework. All rights reserved.
Licensed under the GNU Lesser General Public License.
Return to the MOEA Framework homepage. Visit us on Github!