Class SpectrumToJson

  • All Implemented Interfaces:
    adams.core.AdditionalInformationHandler, adams.core.CleanUpHandler, adams.core.Destroyable, adams.core.GlobalInfoSupporter, adams.core.io.PrettyPrintingSupporter, adams.core.logging.LoggingLevelHandler, adams.core.logging.LoggingSupporter, adams.core.option.OptionHandler, adams.core.QuickInfoSupporter, adams.core.ShallowCopySupporter<adams.data.conversion.AbstractConversion>, adams.core.SizeOfHandler, adams.core.Stoppable, adams.data.conversion.Conversion, Serializable

    public class SpectrumToJson
    extends adams.data.conversion.AbstractConversion
    implements adams.core.io.PrettyPrintingSupporter
    Turns a spectrum into a JSON string.
    Output format:
    - 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
    }
    }


    -logging-level <OFF|SEVERE|WARNING|INFO|CONFIG|FINE|FINER|FINEST> (property: loggingLevel)
        The logging level for outputting errors and debugging output.
        default: WARNING
     
    -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.conversion.AbstractConversion

        m_Input, m_Output, m_Owner, m_Stopped
      • Fields inherited from class adams.core.option.AbstractOptionHandler

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

        m_Logger, m_LoggingIsEnabled, m_LoggingLevel
    • Constructor Summary

      Constructors 
      Constructor Description
      SpectrumToJson()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Class accepts()
      Returns the class that is accepted as input.
      void defineOptions()
      Adds options to the internal list of options.
      protected Object doConvert()
      Performs the actual conversion.
      Class generates()
      Returns the class that is generated as output.
      adams.data.report.Field[] getMetaDataValues()
      Returns the meta-data values to output.
      boolean getPrettyPrinting()
      Returns whether pretty-printing is used or not.
      String getQuickInfo()
      Returns a quick info about the object, which can be displayed in the GUI.
      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.
      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.
      • Methods inherited from class adams.data.conversion.AbstractConversion

        checkData, cleanUp, convert, getAdditionalInformation, getInput, getInput, getOutput, getOutput, getOwner, reset, setInput, setOwner, shallowCopy, shallowCopy, stopExecution
      • Methods inherited from class adams.core.option.AbstractOptionHandler

        cleanUpOptions, destroy, finishInit, getDefaultLoggingLevel, getOptionManager, initialize, 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

      • SpectrumToJson

        public SpectrumToJson()
    • 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.core.option.AbstractOptionHandler
      • 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.
      • getQuickInfo

        public String getQuickInfo()
        Returns a quick info about the object, which can be displayed in the GUI.
        Specified by:
        getQuickInfo in interface adams.core.QuickInfoSupporter
        Overrides:
        getQuickInfo in class adams.data.conversion.AbstractConversion
        Returns:
        null if no info available, otherwise short string
      • accepts

        public Class accepts()
        Returns the class that is accepted as input.
        Specified by:
        accepts in interface adams.data.conversion.Conversion
        Specified by:
        accepts in class adams.data.conversion.AbstractConversion
        Returns:
        the class
      • generates

        public Class generates()
        Returns the class that is generated as output.
        Specified by:
        generates in interface adams.data.conversion.Conversion
        Specified by:
        generates in class adams.data.conversion.AbstractConversion
        Returns:
        the class
      • doConvert

        protected Object doConvert()
                            throws Exception
        Performs the actual conversion.
        Specified by:
        doConvert in class adams.data.conversion.AbstractConversion
        Returns:
        the converted data
        Throws:
        Exception - if something goes wrong with the conversion