Class CsvTemporalRangeTariffParser

java.lang.Object
net.solarnetwork.domain.tariff.CsvTemporalRangeTariffParser

public class CsvTemporalRangeTariffParser extends Object
Parse TemporalRangesTariff rows from CSV data.

The CSV resource must provide a header row, and the names of the tariffs will be taken from there. The first 4 columns of the CSV must be:

  1. month range, as month names, abbreviations, or numbers 1 - 12
  2. day of month range, as numbers 1 - 31
  3. day of week range, as weekday names, abbreviations, or numbers 1-7 (1 = Monday)
  4. time of date range, as hours 0-24 or ISO local times HH:MM-HH-MM

The remaining columns are rate values, and must be numbers that can be parsed as a BigDecimal.

Since:
1.71
Version:
1.0
Author:
matt
  • Constructor Details

    • CsvTemporalRangeTariffParser

      public CsvTemporalRangeTariffParser()
      Constructor.

      The system locale will be used.

    • CsvTemporalRangeTariffParser

      public CsvTemporalRangeTariffParser(Locale locale)
      Constructor.
      Parameters:
      locale - the locale to use, or null to use the system default
  • Method Details

    • parseTariffs

      public List<TemporalRangesTariff> parseTariffs(Reader reader) throws IOException
      Parse tariff rows from a reader.
      Parameters:
      reader - the reader
      Returns:
      the parsed rows, never null
      Throws:
      IOException - if any IO error occurs
      IllegalArgumentException - if any parsing error occurs, like invalid number or range syntax
    • formatCsv

      public void formatCsv(List<TemporalRangesTariff> tariffs, Writer writer) throws IOException
      Encode a list of tariffs as CSV data.

      The range columns are formatted using abbreviations if possible. The time range column will be formatted using integer hours if possible, otherwise HH:MM syntax.

      Parameters:
      tariffs - the tariffs to encode
      writer - the writer to write the CSV data to
      Throws:
      IOException - if any IO error occurs
      IllegalArgumentException - if any formatting error occurs