Class ReportFormatter<R extends Report>

  • Type Parameters:
    R - the report type
    Direct Known Subclasses:
    CashFlowReportFormatter, TradeReportFormatter

    public abstract class ReportFormatter<R extends Report>
    extends java.lang.Object
    Common base class for formatting reports into ASCII tables or CSV format.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected ReportFormatter​(FormatSettings<java.lang.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 java.lang.String formatData​(R report, int rowIdx, int colIdx, ReportOutputFormat format)
      Formats a piece of data for display.
      protected java.lang.String formatValue​(java.lang.Object value, ReportOutputFormat format)
      Formats a value into a string.
      protected abstract java.util.List<java.lang.Class<?>> getColumnTypes​(R report)
      Gets the type of the data in each report column.
      void writeAsciiTable​(R report, java.io.OutputStream out)
      Outputs the report as an ASCII table.
      void writeCsv​(R report, java.io.OutputStream out)
      Outputs the report table in CSV format.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ReportFormatter

        protected ReportFormatter​(FormatSettings<java.lang.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,
                             java.io.OutputStream out)
        Outputs the report table in CSV format.
        Parameters:
        report - the report
        out - the output stream to write to
      • writeAsciiTable

        public void writeAsciiTable​(R report,
                                    java.io.OutputStream out)
        Outputs the report as an ASCII table.
        Parameters:
        report - the report
        out - the output stream to write to
      • getColumnTypes

        protected abstract java.util.List<java.lang.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 java.lang.String formatData​(R report,
                                                       int rowIdx,
                                                       int colIdx,
                                                       ReportOutputFormat format)
        Formats a piece of data for display.
        Parameters:
        report - the report containing the data
        rowIdx - the row index of the data
        colIdx - the column index of the data
        format - the report output format
        Returns:
        the formatted data
      • formatValue

        protected java.lang.String formatValue​(java.lang.Object value,
                                               ReportOutputFormat format)
        Formats a value into a string.
        Parameters:
        value - the value
        format - the format that controls how the value is formatted
        Returns:
        the formatted value