net.sourceforge.openforecast.output
Class DelimitedTextOutputter

java.lang.Object
  extended by net.sourceforge.openforecast.output.DelimitedTextOutputter
All Implemented Interfaces:
Outputter

public class DelimitedTextOutputter
extends 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 the setDelimiter(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, use setOutputHeaderRow(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
Author:
Steven R. Gould

Constructor Summary
DelimitedTextOutputter(File file)
          Constructs a new DelimitedTextOutputter that writes its output to the given file.
DelimitedTextOutputter(File file, boolean append)
          Constructs a new DelimitedTextOutputter that writes its output to the given file.
DelimitedTextOutputter(String filename)
          Constructs a new DelimitedTextOutputter that writes its output to the named file.
DelimitedTextOutputter(String filename, boolean append)
          Constructs a new DelimitedTextOutputter that writes its output to the named file.
DelimitedTextOutputter(Writer writer)
          Constructs a new DelimitedTextOutputter that writes its output to the given Writer object.
 
Method Summary
 void close()
          Close the DelimitedTextOutputter, flushing it first.
 String getDelimiter()
          Returns the current field delimiter.
 String getDependentVariableName()
          Returns the current name to be used as the dependent variable name when outputting a header row.
 void output(DataPoint dataPoint)
          Outputs the given DataPoint to the current Writer.
 void output(DataSet dataSet)
          Writes a DataSet - a collection of DataPoints - to the current writer.
 void setDelimiter(String delimiter)
          Sets the field delimiter to the given String.
 void setDependentVariableName(String name)
          Sets the name/label to be used as the dependent variable name when outputting a header row.
 void setOutputHeaderRow(boolean outputHeaderRow)
          Enables/Disables the output of the header row containing column/field names.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DelimitedTextOutputter

public DelimitedTextOutputter(String filename)
                       throws IOException
Constructs 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:
IOException - if the specified file is not found or if some other I/O error occurs.

DelimitedTextOutputter

public DelimitedTextOutputter(String filename,
                              boolean append)
                       throws IOException
Constructs 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:
IOException - if the specified file is not found or if some other I/O error occurs.

DelimitedTextOutputter

public DelimitedTextOutputter(File file)
                       throws IOException
Constructs 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:
IOException - if the specified file is not found or if some other I/O error occurs.

DelimitedTextOutputter

public DelimitedTextOutputter(File file,
                              boolean append)
                       throws IOException
Constructs 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:
IOException - if the specified file is not found or if some other I/O error occurs.

DelimitedTextOutputter

public DelimitedTextOutputter(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 String getDelimiter()
Returns the current field delimiter. By default, this is set to be a comma. The value used can be overridden using the setDelimiter(java.lang.String) method, before invoking output.

Returns:
the current delimiter that will be used to separate fields.

setDelimiter

public void setDelimiter(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 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.

Specified by:
output in interface Outputter
Parameters:
dataSet - the DataSet to be output to the current writer.
Throws:
IOException - if an I/O error occurs.

output

public void output(DataPoint dataPoint)
            throws IOException
Outputs the given DataPoint to the current Writer.

Parameters:
dataPoint - the DataPoint to output to the current Writer.
Throws:
IOException - if an I/O error occurs.

close

public void close()
           throws IOException
Close 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:
IOException - if an I/O error occurs.

getDependentVariableName

public 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 using setDependentVariableName(java.lang.String).

Returns:
the current name to be used as the dependent variable name when outputting a header row.

setDependentVariableName

public void setDependentVariableName(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 the output(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.


OpenForecast, Copyright (c) Steven Gould, 2002-2011