Class JsonSpectrumWriter

  • All Implemented Interfaces:
    adams.core.AdditionalInformationHandler, adams.core.CleanUpHandler, adams.core.Destroyable, adams.core.GlobalInfoSupporter, adams.core.io.FileFormatHandler, adams.core.io.PrettyPrintingSupporter, adams.core.logging.LoggingLevelHandler, adams.core.logging.LoggingSupporter, adams.core.option.OptionHandler, adams.core.ShallowCopySupporter<adams.data.io.output.AbstractDataContainerWriter>, adams.core.SizeOfHandler, Serializable, Comparable

    public class JsonSpectrumWriter
    extends AbstractSpectrumWriter
    implements adams.core.io.PrettyPrintingSupporter
    Writes spectra in JSON format.
    Output format for single spectrum:
    - outputting the complete report:
    {
    "id": "someid",
    "format": "NIR",
    "waves": [1.0, 2.0],
    "amplitudes": [1.1, 2.1],
    "report": {
    "Sample ID": "someid",
    "GLV2": 1.123,
    "valid": true
    }
    }

    - outputting specific reference and meta-data values:
    {
    "id": "someid",
    "format": "NIR",
    "waves": [1.0, 2.0],
    "amplitudes": [1.1, 2.1],
    "reference": {
    "GLV2": 1.123
    },
    "meta-data": {
    "valid": true
    }
    }

    Multiple spectra get wrapped in an array called 'spectra'.

    -logging-level <OFF|SEVERE|WARNING|INFO|CONFIG|FINE|FINER|FINEST> (property: loggingLevel)
        The logging level for outputting errors and debugging output.
        default: WARNING
     
    -output <adams.core.io.PlaceholderFile> (property: output)
        The file to write the container to.
        default: ${TMP}/out.tmp
     
    -use-reference-and-metadata <boolean> (property: useReferenceAndMetaData)
        If enabled, the only the specified reference and meta-data report values
        are output (in separate sections).
        default: false
     
    -reference-value <adams.data.report.Field> [-reference-value ...] (property: referenceValues)
        The reference values to output.
        default:
     
    -metadata-value <adams.data.report.Field> [-metadata-value ...] (property: metaDataValues)
        The meta-data values to output.
        default:
     
    -pretty-printing <boolean> (property: prettyPrinting)
        If enabled, the output is printed in a 'pretty' format.
        default: false
     
    Author:
    FracPete (fracpete at waikato dot ac dot nz)
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected adams.data.report.Field[] m_MetaDataValues
      the meta-data values.
      protected boolean m_PrettyPrinting
      whether to use pretty-printing.
      protected adams.data.report.Field[] m_ReferenceValues
      the reference values.
      protected boolean m_UseReferenceAndMetaData
      whether to output speficied reference and meta-data values.
      • Fields inherited from class adams.data.io.output.AbstractDataContainerWriter

        m_Output, m_OutputIsFile
      • Fields inherited from class adams.core.option.AbstractOptionHandler

        m_OptionManager
      • Fields inherited from class adams.core.logging.LoggingObject

        m_Logger, m_LoggingIsEnabled, m_LoggingLevel
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean canWriteMultiple()
      Returns whether writing of multiple containers is supported.
      void defineOptions()
      Adds options to the internal list of options.
      String getFormatDescription()
      Returns a string describing the format (used in the file chooser).
      String[] getFormatExtensions()
      Returns the extension(s) of the format.
      adams.data.report.Field[] getMetaDataValues()
      Returns the meta-data values to output.
      boolean getPrettyPrinting()
      Returns whether pretty-printing is used or not.
      adams.data.report.Field[] getReferenceValues()
      Returns the reference values to output.
      boolean getUseReferenceAndMetaData()
      Returns whether only the specified reference and meta-data report values are output (in separate sections).
      String globalInfo()
      Returns a string describing the object.
      protected void initialize()
      Initializes the members.
      String metaDataValuesTipText()
      Returns the tip text for this property.
      String prettyPrintingTipText()
      Returns the tip text for this property.
      String referenceValuesTipText()
      Returns the tip text for this property.
      void setMetaDataValues​(adams.data.report.Field[] value)
      Sets the meta-data values to output.
      void setPrettyPrinting​(boolean value)
      Sets whether to use pretty-printing or not.
      void setReferenceValues​(adams.data.report.Field[] value)
      Sets the reference values to output.
      void setUseReferenceAndMetaData​(boolean value)
      Sets whether only the specified reference and meta-data report values are output (in separate sections).
      String useReferenceAndMetaDataTipText()
      Returns the tip text for this property.
      protected boolean writeData​(List<Spectrum> data)
      Performs the actual writing.
      • Methods inherited from class adams.data.io.output.AbstractDataContainerWriter

        checkData, cleanUp, compareTo, destroy, equals, forCommandLine, forName, getAdditionalInformation, getDefaultFormatExtension, getOutput, isOutputFile, outputTipText, reset, setOutput, shallowCopy, shallowCopy, write, write
      • Methods inherited from class adams.core.option.AbstractOptionHandler

        cleanUpOptions, finishInit, getDefaultLoggingLevel, getOptionManager, loggingLevelTipText, newOptionManager, setLoggingLevel, toCommandLine, toString
      • Methods inherited from class adams.core.logging.LoggingObject

        configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
      • Methods inherited from interface adams.core.logging.LoggingLevelHandler

        getLoggingLevel
    • Field Detail

      • m_UseReferenceAndMetaData

        protected boolean m_UseReferenceAndMetaData
        whether to output speficied reference and meta-data values.
      • m_ReferenceValues

        protected adams.data.report.Field[] m_ReferenceValues
        the reference values.
      • m_MetaDataValues

        protected adams.data.report.Field[] m_MetaDataValues
        the meta-data values.
      • m_PrettyPrinting

        protected boolean m_PrettyPrinting
        whether to use pretty-printing.
    • Constructor Detail

      • JsonSpectrumWriter

        public JsonSpectrumWriter()
    • Method Detail

      • globalInfo

        public String globalInfo()
        Returns a string describing the object.
        Specified by:
        globalInfo in interface adams.core.GlobalInfoSupporter
        Specified by:
        globalInfo in class adams.core.option.AbstractOptionHandler
        Returns:
        a description suitable for displaying in the gui
      • defineOptions

        public void defineOptions()
        Adds options to the internal list of options.
        Specified by:
        defineOptions in interface adams.core.option.OptionHandler
        Overrides:
        defineOptions in class adams.data.io.output.AbstractDataContainerWriter<Spectrum>
      • setUseReferenceAndMetaData

        public void setUseReferenceAndMetaData​(boolean value)
        Sets whether only the specified reference and meta-data report values are output (in separate sections).
        Parameters:
        value - true if to use pretty-printing
      • getUseReferenceAndMetaData

        public boolean getUseReferenceAndMetaData()
        Returns whether only the specified reference and meta-data report values are output (in separate sections).
        Returns:
        true if to use pretty-printing
      • useReferenceAndMetaDataTipText

        public String useReferenceAndMetaDataTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setReferenceValues

        public void setReferenceValues​(adams.data.report.Field[] value)
        Sets the reference values to output.
        Parameters:
        value - the fields
      • getReferenceValues

        public adams.data.report.Field[] getReferenceValues()
        Returns the reference values to output.
        Returns:
        the fields
      • referenceValuesTipText

        public String referenceValuesTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setMetaDataValues

        public void setMetaDataValues​(adams.data.report.Field[] value)
        Sets the meta-data values to output.
        Parameters:
        value - the fields
      • getMetaDataValues

        public adams.data.report.Field[] getMetaDataValues()
        Returns the meta-data values to output.
        Returns:
        the fields
      • metaDataValuesTipText

        public String metaDataValuesTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setPrettyPrinting

        public void setPrettyPrinting​(boolean value)
        Sets whether to use pretty-printing or not.
        Specified by:
        setPrettyPrinting in interface adams.core.io.PrettyPrintingSupporter
        Parameters:
        value - true if to use pretty-printing
      • getPrettyPrinting

        public boolean getPrettyPrinting()
        Returns whether pretty-printing is used or not.
        Specified by:
        getPrettyPrinting in interface adams.core.io.PrettyPrintingSupporter
        Returns:
        true if to use pretty-printing
      • prettyPrintingTipText

        public String prettyPrintingTipText()
        Returns the tip text for this property.
        Specified by:
        prettyPrintingTipText in interface adams.core.io.PrettyPrintingSupporter
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • getFormatDescription

        public String getFormatDescription()
        Returns a string describing the format (used in the file chooser).
        Specified by:
        getFormatDescription in interface adams.core.io.FileFormatHandler
        Specified by:
        getFormatDescription in class adams.data.io.output.AbstractDataContainerWriter<Spectrum>
        Returns:
        a description suitable for displaying in the file chooser
      • getFormatExtensions

        public String[] getFormatExtensions()
        Returns the extension(s) of the format.
        Specified by:
        getFormatExtensions in interface adams.core.io.FileFormatHandler
        Specified by:
        getFormatExtensions in class adams.data.io.output.AbstractDataContainerWriter<Spectrum>
        Returns:
        the extension(s) (without the dot!)
      • initialize

        protected void initialize()
        Initializes the members.
        Overrides:
        initialize in class adams.core.option.AbstractOptionHandler
      • canWriteMultiple

        public boolean canWriteMultiple()
        Returns whether writing of multiple containers is supported.
        Overrides:
        canWriteMultiple in class AbstractSpectrumWriter
        Returns:
        true if multiple containers are supported
      • writeData

        protected boolean writeData​(List<Spectrum> data)
        Performs the actual writing.
        Specified by:
        writeData in class adams.data.io.output.AbstractDataContainerWriter<Spectrum>
        Parameters:
        data - the data to write
        Returns:
        true if successfully written