Class ReportFormatter<R extends Report>
- java.lang.Object
-
- com.opengamma.strata.report.framework.format.ReportFormatter<R>
-
- Type Parameters:
R
- the report type
- Direct Known Subclasses:
CashFlowReportFormatter
,TradeReportFormatter
public abstract class ReportFormatter<R extends Report> extends Object
Common base class for formatting reports into ASCII tables or CSV format.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
ReportFormatter(FormatSettings<Object> defaultSettings)
Creates a new formatter with a set of default format settings.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract String
formatData(R report, int rowIdx, int colIdx, ReportOutputFormat format)
Formats a piece of data for display.protected String
formatValue(Object value, ReportOutputFormat format)
Formats a value into a string.protected abstract List<Class<?>>
getColumnTypes(R report)
Gets the type of the data in each report column.void
writeAsciiTable(R report, OutputStream out)
Outputs the report as an ASCII table.void
writeCsv(R report, OutputStream out)
Outputs the report table in CSV format.
-
-
-
Constructor Detail
-
ReportFormatter
protected ReportFormatter(FormatSettings<Object> defaultSettings)
Creates a new formatter with a set of default format settings.- Parameters:
defaultSettings
- default format settings, used if there are no settings for a data type.
-
-
Method Detail
-
writeCsv
public void writeCsv(R report, OutputStream out)
Outputs the report table in CSV format.- Parameters:
report
- the reportout
- the output stream to write to
-
writeAsciiTable
public void writeAsciiTable(R report, OutputStream out)
Outputs the report as an ASCII table.- Parameters:
report
- the reportout
- the output stream to write to
-
getColumnTypes
protected abstract List<Class<?>> getColumnTypes(R report)
Gets the type of the data in each report column.If every value in a column is a failure the type will be
Object.class
.- Parameters:
report
- the report- Returns:
- a list of column types
-
formatData
protected abstract String formatData(R report, int rowIdx, int colIdx, ReportOutputFormat format)
Formats a piece of data for display.- Parameters:
report
- the report containing the datarowIdx
- the row index of the datacolIdx
- the column index of the dataformat
- the report output format- Returns:
- the formatted data
-
formatValue
protected String formatValue(Object value, ReportOutputFormat format)
Formats a value into a string.- Parameters:
value
- the valueformat
- the format that controls how the value is formatted- Returns:
- the formatted value
-
-