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 Summary
Constructors Constructor Description AbstractGenerator(Appendable output, String outputName, double maxRelativeOffset, boolean writeUnits)
Simple constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Close the generator.protected void
complain(String key, boolean mandatory)
Complain about a missing value.String
dateToCalendarString(TimeConverter converter, AbsoluteDate date)
Convert a date to calendar string value with high precision.String
dateToString(int year, int month, int day, int hour, int minute, double seconds)
Convert a date to string value with high precision.String
dateToString(TimeConverter converter, AbsoluteDate date)
Convert a date to string value with high precision.String
doubleToString(double value)
Convert a double to string value with high precision.void
enterSection(String name)
Enter into a new section.String
exitSection()
Exit last section.String
getOutputName()
Get the name of the output (for error messages).void
newLine()
Finish current line.String
siToCcsdsName(String siName)
Convert a SI unit name to a CCSDS name.String
unitsListToString(List<Unit> units)
Convert a list of units to a bracketed string.void
writeEntry(String key, char value, boolean mandatory)
Write a single key/value entry.void
writeEntry(String key, double value, Unit unit, boolean mandatory)
Write a single key/value entry.void
writeEntry(String key, int value, boolean mandatory)
Write a single key/value entry.void
writeEntry(String key, Double value, Unit unit, boolean mandatory)
Write a single key/value entry.void
writeEntry(String key, Enum<?> value, boolean mandatory)
Write a single key/value entry.void
writeEntry(String key, List<String> value, boolean mandatory)
Write a single key/value entry.void
writeEntry(String key, TimeConverter converter, AbsoluteDate date, boolean forceCalendar, boolean mandatory)
Write a single key/value entry.void
writeRawData(char data)
Write raw data.void
writeRawData(CharSequence data)
Write raw data.boolean
writeUnits(Unit unit)
Check if unit must be written.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.orekit.files.ccsds.utils.generation.Generator
endMessage, getFormat, startMessage, writeComments, writeEntry, writeEntry
-
-
-
-
Constructor Detail
-
AbstractGenerator
public AbstractGenerator(Appendable output, String outputName, double maxRelativeOffset, boolean writeUnits)
Simple constructor.- Parameters:
output
- destination of generated outputoutputName
- output name for error messagesmaxRelativeOffset
- 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 interfaceGenerator
- 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
-
close
public void close() throws IOException
Close the generator.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceGenerator
- Throws:
IOException
- if an I/O error occurs.
-
newLine
public void newLine() throws IOException
Finish current line.- Specified by:
newLine
in interfaceGenerator
- 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 interfaceGenerator
- Parameters:
key
- the keyword to writevalue
- the value to writemandatory
- 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 interfaceGenerator
- Parameters:
key
- the keyword to writevalue
- the value to writemandatory
- 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 interfaceGenerator
- Parameters:
key
- the keyword to writeconverter
- converter to use for datesdate
- the date to writeforceCalendar
- if true, the date is forced to calendar formatmandatory
- 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 interfaceGenerator
- Parameters:
key
- the keyword to writevalue
- the value to write (in SI units)unit
- output unitmandatory
- 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 interfaceGenerator
- Parameters:
key
- the keyword to writevalue
- the value to write (in SI units)unit
- output unitmandatory
- 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 interfaceGenerator
- Parameters:
key
- the keyword to writevalue
- the value to writemandatory
- 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 ofvalue
is treated as valid. UseGenerator.writeEntry(String, Integer, boolean)
for integer values that may not be present.- Specified by:
writeEntry
in interfaceGenerator
- Parameters:
key
- the keyword to writevalue
- the value to writemandatory
- if true, null values triggers exception, otherwise they are silently ignored.- Throws:
IOException
- if an I/O error occurs.- See Also:
Generator.writeEntry(String, Integer, boolean)
-
writeRawData
public void writeRawData(char data) throws IOException
Write raw data.- Specified by:
writeRawData
in interfaceGenerator
- 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 interfaceGenerator
- 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 interfaceGenerator
- 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 interfaceGenerator
- 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 writemandatory
- 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 interfaceGenerator
- 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 interfaceGenerator
- Parameters:
converter
- converter for datesdate
- 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 interfaceGenerator
- Parameters:
converter
- converter for datesdate
- 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 interfaceGenerator
- Parameters:
year
- yearmonth
- monthday
- dayhour
- hourminute
- minuteseconds
- 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 interfaceGenerator
- 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 interfaceGenerator
- Parameters:
siName
- si unit name- Returns:
- CCSDS name for the unit
-
-