public abstract class AbstractCommandLineInterface extends Object
java YourClassCLI -input fileinput -output fileoutputwhere fileinput and fileoutput represent two filepaths. Please note that fileinput must point to an existing input file while if fileoutput does not exist the file will create (otherwise will be overwritten).
Modifier and Type | Field and Description |
---|---|
static String |
INPUT
Default name for the input file
|
static String |
OUTPUT
Default name for the output file
|
protected Map<String,String> |
params |
protected String |
usage
Default usage string, overwrite it to change the message
|
Constructor and Description |
---|
AbstractCommandLineInterface()
Do not use this costructor
|
AbstractCommandLineInterface(String[] args)
Default costructor
|
AbstractCommandLineInterface(String[] args,
String[] parameters) |
AbstractCommandLineInterface(String[] args,
String[] parameters,
String usage) |
Modifier and Type | Method and Description |
---|---|
protected void |
closeInput()
Closes the input file, terminates the cli if an error
occurs.
|
protected void |
closeInputAndOuput()
Closes both input and output file, terminates the cli if an error
occurs.
|
protected void |
closeOutput()
Closes the output file, terminates the cli if an error
occurs.
|
protected double |
getDoubleParam(String param)
Returns the double value of a particular parameter
|
protected String |
getInput()
Returns the input filename.
|
protected int |
getIntParam(String param)
Returns the int value of a particular parameter
|
protected String |
getOutput()
Returns the output filename.
|
protected String |
getParam(String param)
Returns the value of a particular parameter
|
String |
getUsage()
Returns the usage message.
|
protected void |
openInput()
Opens the file given in input, if the file ends with .gz, it uses
a compressed reader.
|
protected void |
openInputAndOutput()
Opens both input and output, terminates the cli if an error
occurs.
|
protected void |
openOutput()
Open the file given in output, if the file ends with .gz, it uses
a compressed writer.
|
protected String |
readLineFromInput()
Reads the next line on the inputfile, if the file ends returns null.
|
void |
setUsage(String usage)
Sets the usage message.
|
protected void |
writeInOutput(String str)
Writes text in the output file.
|
protected void |
writeLineInOutput(String line)
Writes a line in the output file.
|
public static final String INPUT
public static final String OUTPUT
protected String usage
public AbstractCommandLineInterface()
public AbstractCommandLineInterface(String[] args)
args
- the main argspublic AbstractCommandLineInterface(String[] args, String[] parameters)
args
- the main argsparameters
- the parameters accepted by this cli, if different by the default.protected String getInput()
protected String getOutput()
protected String getParam(String param)
param
- the parameterprotected int getIntParam(String param)
param
- the parameterprotected double getDoubleParam(String param)
param
- the parameterprotected void openInput()
protected void openOutput()
protected String readLineFromInput()
protected void writeLineInOutput(String line)
protected void writeInOutput(String str)
protected void openInputAndOutput()
protected void closeInput()
protected void closeOutput()
protected void closeInputAndOuput()
public String getUsage()
public void setUsage(String usage)
usage
- the usage messageCopyright © 2013. All rights reserved.