public abstract class AbstractGenerator extends Object implements Generator
Constructor and Description |
---|
AbstractGenerator(Appendable output,
String outputName,
boolean writeUnits)
Simple constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the generator.
|
protected void |
complain(String key,
boolean mandatory)
Complain about a missing value.
|
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,
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,
int 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 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.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
endMessage, getFormat, startMessage, writeComments, writeEntry
public AbstractGenerator(Appendable output, String outputName, boolean writeUnits)
output
- destination of generated outputoutputName
- output name for error messageswriteUnits
- if true, units must be writtenpublic String getOutputName()
getOutputName
in interface Generator
public boolean writeUnits(Unit unit)
unit
- entry unitpublic void close() throws IOException
close
in interface AutoCloseable
close
in interface Generator
IOException
- if an I/O error occurs.public void newLine() throws IOException
newLine
in interface Generator
IOException
- if an I/O error occurs.public void writeEntry(String key, List<String> value, boolean mandatory) throws IOException
writeEntry
in interface Generator
key
- the keyword to writevalue
- the value to writemandatory
- if true, null values triggers exception, otherwise they are silently ignoredIOException
- if an I/O error occurs.public void writeEntry(String key, Enum<?> value, boolean mandatory) throws IOException
writeEntry
in interface Generator
key
- the keyword to writevalue
- the value to writemandatory
- if true, null values triggers exception, otherwise they are silently ignoredIOException
- if an I/O error occurs.public void writeEntry(String key, TimeConverter converter, AbsoluteDate date, boolean mandatory) throws IOException
writeEntry
in interface Generator
key
- the keyword to writeconverter
- converter to use for datesdate
- the date to writemandatory
- if true, null values triggers exception, otherwise they are silently ignoredIOException
- if an I/O error occurs.public void writeEntry(String key, double value, Unit unit, boolean mandatory) throws IOException
writeEntry
in interface Generator
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 ignoredIOException
- if an I/O error occurs.public void writeEntry(String key, Double value, Unit unit, boolean mandatory) throws IOException
writeEntry
in interface Generator
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 ignoredIOException
- if an I/O error occurs.public void writeEntry(String key, char value, boolean mandatory) throws IOException
writeEntry
in interface Generator
key
- the keyword to writevalue
- the value to writemandatory
- if true, null values triggers exception, otherwise they are silently ignoredIOException
- if an I/O error occurs.public void writeEntry(String key, int value, boolean mandatory) throws IOException
writeEntry
in interface Generator
key
- the keyword to writevalue
- the value to writemandatory
- if true, null values triggers exception, otherwise they are silently ignoredIOException
- if an I/O error occurs.public void writeRawData(char data) throws IOException
writeRawData
in interface Generator
data
- raw data to writeIOException
- if an I/O error occurs.public void writeRawData(CharSequence data) throws IOException
writeRawData
in interface Generator
data
- raw data to writeIOException
- if an I/O error occurs.public void enterSection(String name) throws IOException
enterSection
in interface Generator
name
- section nameIOException
- if an I/O error occurs.public String exitSection() throws IOException
exitSection
in interface Generator
IOException
- if an I/O error occurs.protected void complain(String key, boolean mandatory)
key
- the keyword to writemandatory
- if true, triggers en exception, otherwise do nothingpublic String doubleToString(double value)
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.
doubleToString
in interface Generator
value
- value to formatDouble.NaN
public String dateToString(TimeConverter converter, AbsoluteDate date)
dateToString
in interface Generator
converter
- converter for datesdate
- date to writepublic String dateToString(int year, int month, int day, int hour, int minute, double seconds)
dateToString
in interface Generator
year
- yearmonth
- monthday
- dayhour
- hourminute
- minuteseconds
- secondspublic String unitsListToString(List<Unit> units)
unitsListToString
in interface Generator
units
- lists to output (may be null or empty)public String siToCcsdsName(String siName)
siToCcsdsName
in interface Generator
siName
- si unit nameCopyright © 2002-2022 CS GROUP. All rights reserved.