Class AbstractGenerator

java.lang.Object
org.orekit.files.ccsds.utils.generation.AbstractGenerator
All Implemented Interfaces:
AutoCloseable, Generator
Direct Known Subclasses:
KvnGenerator, XmlGenerator

public abstract class AbstractGenerator extends Object implements Generator
Base class for both Key-Value Notation and eXtended Markup Language generators for CCSDS messages.
Since:
11.0
Author:
Luc Maisonobe
  • Constructor Details

    • AbstractGenerator

      protected AbstractGenerator(Appendable output, String outputName, double maxRelativeOffset, boolean writeUnits, Formatter formatter)
      Simple constructor.
      Parameters:
      output - destination of generated output
      outputName - output name for error messages
      maxRelativeOffset - maximum offset in seconds to use relative dates (if a date is too far from reference, it will be displayed as calendar elements)
      writeUnits - if true, units must be written
      formatter - how to format date and double to string.
  • Method Details

    • getOutputName

      public String getOutputName()
      Get the name of the output (for error messages).
      Specified by:
      getOutputName in interface Generator
      Returns:
      name of the output
    • getFormatter

      public Formatter getFormatter()
      Used to format dates and doubles to string.
      Specified by:
      getFormatter in interface Generator
      Returns:
      formatter
    • writeUnits

      public boolean writeUnits(Unit unit)
      Check if unit must be written.
      Parameters:
      unit - entry unit
      Returns:
      true if units must be written
    • close

      public void close() throws IOException
      Close the generator.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Generator
      Throws:
      IOException - if an I/O error occurs.
    • newLine

      public void newLine() throws IOException
      Finish current line.
      Specified by:
      newLine in interface Generator
      Throws:
      IOException - if an I/O error occurs.
    • writeEntry

      public void writeEntry(String key, List<String> value, boolean mandatory) throws IOException
      Write a single key/value entry.
      Specified by:
      writeEntry in interface Generator
      Parameters:
      key - the keyword to write
      value - the value to write
      mandatory - if true, null values triggers exception, otherwise they are silently ignored
      Throws:
      IOException - if an I/O error occurs.
    • writeEntry

      public void writeEntry(String key, Enum<?> value, boolean mandatory) throws IOException
      Write a single key/value entry.
      Specified by:
      writeEntry in interface Generator
      Parameters:
      key - the keyword to write
      value - the value to write
      mandatory - if true, null values triggers exception, otherwise they are silently ignored
      Throws:
      IOException - if an I/O error occurs.
    • writeEntry

      public void writeEntry(String key, TimeConverter converter, AbsoluteDate date, boolean forceCalendar, boolean mandatory) throws IOException
      Write a single key/value entry.
      Specified by:
      writeEntry in interface Generator
      Parameters:
      key - the keyword to write
      converter - converter to use for dates
      date - the date to write
      forceCalendar - if true, the date is forced to calendar format
      mandatory - if true, null values triggers exception, otherwise they are silently ignored
      Throws:
      IOException - if an I/O error occurs.
    • writeEntry

      public void writeEntry(String key, double value, Unit unit, boolean mandatory) throws IOException
      Write a single key/value entry.
      Specified by:
      writeEntry in interface Generator
      Parameters:
      key - the keyword to write
      value - the value to write (in SI units)
      unit - output unit
      mandatory - if true, null values triggers exception, otherwise they are silently ignored
      Throws:
      IOException - if an I/O error occurs.
    • writeEntry

      public void writeEntry(String key, Double value, Unit unit, boolean mandatory) throws IOException
      Write a single key/value entry.
      Specified by:
      writeEntry in interface Generator
      Parameters:
      key - the keyword to write
      value - the value to write (in SI units)
      unit - output unit
      mandatory - if true, null values triggers exception, otherwise they are silently ignored
      Throws:
      IOException - if an I/O error occurs.
    • writeEntry

      public void writeEntry(String key, char value, boolean mandatory) throws IOException
      Write a single key/value entry.
      Specified by:
      writeEntry in interface Generator
      Parameters:
      key - the keyword to write
      value - the value to write
      mandatory - if true, null values triggers exception, otherwise they are silently ignored
      Throws:
      IOException - if an I/O error occurs.
    • writeEntry

      public void writeEntry(String key, int value, boolean mandatory) throws IOException
      Write a single key/value entry.

      Note that the mandatory flag has no effect and a value is always written because the whole domain of value is treated as valid. Use Generator.writeEntry(String, Integer, boolean) for integer values that may not be present.

      Specified by:
      writeEntry in interface Generator
      Parameters:
      key - the keyword to write
      value - the value to write
      mandatory - if true, null values triggers exception, otherwise they are silently ignored.
      Throws:
      IOException - if an I/O error occurs.
      See Also:
    • writeRawData

      public void writeRawData(char data) throws IOException
      Write raw data.
      Specified by:
      writeRawData in interface Generator
      Parameters:
      data - raw data to write
      Throws:
      IOException - if an I/O error occurs.
    • writeRawData

      public void writeRawData(CharSequence data) throws IOException
      Write raw data.
      Specified by:
      writeRawData in interface Generator
      Parameters:
      data - raw data to write
      Throws:
      IOException - if an I/O error occurs.
    • enterSection

      public void enterSection(String name) throws IOException
      Enter into a new section.
      Specified by:
      enterSection in interface Generator
      Parameters:
      name - section name
      Throws:
      IOException - if an I/O error occurs.
    • exitSection

      public String exitSection() throws IOException
      Exit last section.
      Specified by:
      exitSection in interface Generator
      Returns:
      section name
      Throws:
      IOException - if an I/O error occurs.
    • complain

      protected void complain(String key, boolean mandatory)
      Complain about a missing value.
      Parameters:
      key - the keyword to write
      mandatory - if true, triggers en exception, otherwise do nothing
    • doubleToString

      public String doubleToString(double value)
      Convert a double to string value with high precision.

      We don't want to loose internal accuracy when writing doubles but we also don't want to have ugly representations like STEP = 1.25000000000000000 so we try a few simple formats first and fall back to scientific notation if it doesn't work.

      Specified by:
      doubleToString in interface Generator
      Parameters:
      value - value to format
      Returns:
      formatted value, with all original value accuracy preserved, or null if value is null or Double.NaN
    • dateToString

      public String dateToString(TimeConverter converter, AbsoluteDate date)
      Convert a date to string value with high precision.
      Specified by:
      dateToString in interface Generator
      Parameters:
      converter - converter for dates
      date - date to write
      Returns:
      date as a string (may be either a relative date or a calendar date)
    • dateToCalendarString

      public String dateToCalendarString(TimeConverter converter, AbsoluteDate date)
      Convert a date to calendar string value with high precision.
      Specified by:
      dateToCalendarString in interface Generator
      Parameters:
      converter - converter for dates
      date - date to write
      Returns:
      date as a calendar string
    • dateToString

      public String dateToString(int year, int month, int day, int hour, int minute, double seconds)
      Convert a date to string value with high precision.
      Specified by:
      dateToString in interface Generator
      Parameters:
      year - year
      month - month
      day - day
      hour - hour
      minute - minute
      seconds - seconds
      Returns:
      date as a string
    • unitsListToString

      public String unitsListToString(List<Unit> units)
      Convert a list of units to a bracketed string.
      Specified by:
      unitsListToString in interface Generator
      Parameters:
      units - lists to output (may be null or empty)
      Returns:
      bracketed string (null if units list is null or empty)
    • siToCcsdsName

      public String siToCcsdsName(String siName)
      Convert a SI unit name to a CCSDS name.
      Specified by:
      siToCcsdsName in interface Generator
      Parameters:
      siName - si unit name
      Returns:
      CCSDS name for the unit