Class 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 Detail

      • AbstractGenerator

        public AbstractGenerator​(Appendable output,
                                 String outputName,
                                 double maxRelativeOffset,
                                 boolean writeUnits)
        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
    • Method Detail

      • getOutputName

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

        public boolean writeUnits​(Unit unit)
        Check if unit must be written.
        Parameters:
        unit - entry unit
        Returns:
        true if units must be written
      • 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.
        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.
      • 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.
      • 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