Class DelimitedTextOutputter
- java.lang.Object
-
- net.sourceforge.openforecast.output.DelimitedTextOutputter
-
- All Implemented Interfaces:
- Outputter
public class DelimitedTextOutputter extends java.lang.Object implements Outputter
Defines an Outputter that can be used to write a DataSet in any text delimited format. For example, space or tab delimited, comma-delimited (also known as CSV, Comma Separated Values, format). The default delimiter is the comma, so the resulting output will be in CSV format. This can be over-ridden using thesetDelimiter(java.lang.String)method. Using the default delimiter (the comma), this class provides for a quick and easy "export" of forecast data points to a variety of other applications such as Microsoft Excel or any other spreadsheet application.The last value on each row is assumed to represent the dependent variable. For example, if the independent variables are represented by x1, x2, x3 and so on, and the dependent variable is represented by y, then an output row will be of the form:
x1, x2, ..., xi, y
For example, the following output would be produced by the data points (1,3), (2,5), (3,6), and (4,7):
1,3 2,5 3,6 4,7
where the values 3, 5, 6 and 7 are the forecast - or possibly the observed - values of the dependent variable corresponding to the associated values of the independent variables with the values 1, 2, 3, and 4 respectively. The order of the independent variables is determined by the order of the variables returned by
DataPoint.getIndependentVariableNames(). By default, a header row containing these variable names will be output as the first line of output. To disable this behavior, usesetOutputHeaderRow(boolean)to disable this option.Using the previous example, if the x1 represented time, the output would be:
time,dependent value 1,3 2,5 3,6 4,7
- Since:
- 0.4
-
-
Constructor Summary
Constructors Constructor and Description DelimitedTextOutputter(java.io.File file)Constructs a new DelimitedTextOutputter that writes its output to the given file.DelimitedTextOutputter(java.io.File file, boolean append)Constructs a new DelimitedTextOutputter that writes its output to the given file.DelimitedTextOutputter(java.lang.String filename)Constructs a new DelimitedTextOutputter that writes its output to the named file.DelimitedTextOutputter(java.lang.String filename, boolean append)Constructs a new DelimitedTextOutputter that writes its output to the named file.DelimitedTextOutputter(java.io.Writer writer)Constructs a new DelimitedTextOutputter that writes its output to the given Writer object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidclose()Close the DelimitedTextOutputter, flushing it first.java.lang.StringgetDelimiter()Returns the current field delimiter.java.lang.StringgetDependentVariableName()Returns the current name to be used as the dependent variable name when outputting a header row.voidoutput(DataPoint dataPoint)Outputs the given DataPoint to the current Writer.voidoutput(DataSet dataSet)Writes a DataSet - a collection of DataPoints - to the current writer.voidsetDelimiter(java.lang.String delimiter)Sets the field delimiter to the given String.voidsetDependentVariableName(java.lang.String name)Sets the name/label to be used as the dependent variable name when outputting a header row.voidsetOutputHeaderRow(boolean outputHeaderRow)Enables/Disables the output of the header row containing column/field names.
-
-
-
Constructor Detail
-
DelimitedTextOutputter
public DelimitedTextOutputter(java.lang.String filename) throws java.io.IOExceptionConstructs a new DelimitedTextOutputter that writes its output to the named file.- Parameters:
filename- the name of the file to write the data points to.- Throws:
java.io.IOException- if the specified file is not found or if some other I/O error occurs.
-
DelimitedTextOutputter
public DelimitedTextOutputter(java.lang.String filename, boolean append) throws java.io.IOExceptionConstructs a new DelimitedTextOutputter that writes its output to the named file. If the second argument is true, then output will be appended to the end of the file rather over-writing the file.- Parameters:
filename- the name of the file to write the data points to.append- if true, then output will be appended to the end of the file.- Throws:
java.io.IOException- if the specified file is not found or if some other I/O error occurs.
-
DelimitedTextOutputter
public DelimitedTextOutputter(java.io.File file) throws java.io.IOExceptionConstructs a new DelimitedTextOutputter that writes its output to the given file.- Parameters:
file- the File object specifying the file to write the data points to.- Throws:
java.io.IOException- if the specified file is not found or if some other I/O error occurs.
-
DelimitedTextOutputter
public DelimitedTextOutputter(java.io.File file, boolean append) throws java.io.IOExceptionConstructs a new DelimitedTextOutputter that writes its output to the given file. If the second argument is true, then output will be appended to the end of the file rather over-writing the file.- Parameters:
file- the File object specifying the file to write the data points to.append- if true, then output will be appended to the end of the file.- Throws:
java.io.IOException- if the specified file is not found or if some other I/O error occurs.
-
DelimitedTextOutputter
public DelimitedTextOutputter(java.io.Writer writer)
Constructs a new DelimitedTextOutputter that writes its output to the given Writer object.- Parameters:
writer- the Writer object to which the data points should be output.
-
-
Method Detail
-
getDelimiter
public java.lang.String getDelimiter()
Returns the current field delimiter. By default, this is set to be a comma. The value used can be overridden using thesetDelimiter(java.lang.String)method, before invoking output.- Returns:
- the current delimiter that will be used to separate fields.
-
setDelimiter
public void setDelimiter(java.lang.String delimiter)
Sets the field delimiter to the given String.- Parameters:
delimiter- the new delimiter to use to separate fields.
-
output
public void output(DataSet dataSet) throws java.io.IOException
Writes a DataSet - a collection of DataPoints - to the current writer. The DataSet should contain all DataPoints to be output.Depending on the setting of outputHeaderRow, a header row containing the variable names of the data points will be output. To enable/disable this feature, use the
setOutputHeaderRow(boolean)method.
-
output
public void output(DataPoint dataPoint) throws java.io.IOException
Outputs the given DataPoint to the current Writer.- Parameters:
dataPoint- the DataPoint to output to the current Writer.- Throws:
java.io.IOException- if an I/O error occurs.
-
close
public void close() throws java.io.IOExceptionClose the DelimitedTextOutputter, flushing it first. Once a DelimitedTextOutputter has been closed, further output invocations will cause an IOException to be thrown. Closing a previously-closed stream, however, has no effect.- Throws:
java.io.IOException- if an I/O error occurs.
-
getDependentVariableName
public java.lang.String getDependentVariableName()
Returns the current name to be used as the dependent variable name when outputting a header row. By default, this is simply "dependent value", but can be overridden usingsetDependentVariableName(java.lang.String).- Returns:
- the current name to be used as the dependent variable name when outputting a header row.
-
setDependentVariableName
public void setDependentVariableName(java.lang.String name)
Sets the name/label to be used as the dependent variable name when outputting a header row. Note that if no header row is output, then setting this value will have no impact on the output.- Parameters:
name- the name/label to be use for the dependent variable name in any subsequent output.
-
setOutputHeaderRow
public void setOutputHeaderRow(boolean outputHeaderRow)
Enables/Disables the output of the header row containing column/field names. When theoutput(DataSet)method is invoked, the first row/line will contain a comma-separated list of the column names if this option is enabled before calling the output method.- Parameters:
outputHeaderRow- set to true if the header row is to be output; or false to suppress output of the header row.
-
-
DataMelt 3.0 © DataMelt by jWork.ORG