Package adams.data.io.output
Class AbstractReportWriter<T extends Report>
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.core.logging.CustomLoggingLevelObject
-
- adams.core.option.AbstractOptionHandler
-
- adams.data.io.output.AbstractReportWriter<T>
-
- Type Parameters:
T
- the type of report to handle
- All Implemented Interfaces:
CleanUpHandler
,Destroyable
,GlobalInfoSupporter
,FileFormatHandler
,LoggingLevelHandler
,LoggingSupporter
,OptionHandler
,ShallowCopySupporter<AbstractReportWriter>
,SizeOfHandler
,ReportWriter<T>
,Serializable
,Comparable
- Direct Known Subclasses:
AbstractMultiReportWriter
,AbstractSimpleCSVReportWriter
,AbstractSimpleJsonReportWriter
,AbstractSimpleReportWriter
,ObjectLocationsSpreadSheetWriter
,OpexObjectLocationsWriter
,ViaAnnotationsReportWriter
,YoloAnnotationsReportWriter
public abstract class AbstractReportWriter<T extends Report> extends AbstractOptionHandler implements Comparable, CleanUpHandler, ReportWriter<T>, ShallowCopySupporter<AbstractReportWriter>, FileFormatHandler
Abstract ancestor for writers that write reports to files in various formats.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected PlaceholderFile
m_Output
the file to write to.-
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 AbstractReportWriter()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
checkData(T data)
The default implementation only checks whether the provided file is an actual file and whether it exists (if m_OutputIsFile is TRUE).void
cleanUp()
Can be used to free up memory.int
compareTo(Object o)
Compares this object with the specified object for order.void
defineOptions()
Adds options to the internal list of options.void
destroy()
Frees up memory in a "destructive" non-reversible way.boolean
equals(Object o)
Returns whether the two objects are the same.static AbstractReportWriter
forCommandLine(String cmdline)
Instantiates the chromatogram writer from the given commandline (i.e., classname and optional options).static AbstractReportWriter
forName(String classname, String[] options)
Instantiates the chromatogram writer with the given options.String
getDefaultFormatExtension()
Returns the default extension of the format.abstract String
getFormatDescription()
Returns a string describing the format (used in the file chooser).abstract String[]
getFormatExtensions()
Returns the extension of the format.PlaceholderFile
getOutput()
The file/directory to write to.static String[]
getWriters()
Returns a list with classnames of writers.String
outputTipText()
Returns the tip text for this property.protected void
reset()
Resets the writer (but does not clear the input data!).void
setOutput(PlaceholderFile value)
Sets the file/directory to write to.AbstractReportWriter
shallowCopy()
Returns a shallow copy of itself, i.e., based on the commandline options.AbstractReportWriter
shallowCopy(boolean expand)
Returns a shallow copy of itself, i.e., based on the commandline options.boolean
write(T data)
Performs checks and writes the data.protected abstract boolean
writeData(T data)
Performs the actual writing.-
Methods inherited from class adams.core.option.AbstractOptionHandler
cleanUpOptions, finishInit, getDefaultLoggingLevel, getOptionManager, globalInfo, initialize, loggingLevelTipText, newOptionManager, setLoggingLevel, toCommandLine, toString
-
Methods inherited from class adams.core.logging.LoggingObject
configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface adams.core.logging.LoggingLevelHandler
getLoggingLevel
-
-
-
-
Field Detail
-
m_Output
protected PlaceholderFile m_Output
the file to write to.
-
-
Method Detail
-
getFormatDescription
public abstract String getFormatDescription()
Returns a string describing the format (used in the file chooser).- Specified by:
getFormatDescription
in interfaceFileFormatHandler
- Returns:
- a description suitable for displaying in the file chooser
-
getFormatExtensions
public abstract String[] getFormatExtensions()
Returns the extension of the format.- Specified by:
getFormatExtensions
in interfaceFileFormatHandler
- Returns:
- the extension (without the dot!)
-
getDefaultFormatExtension
public String getDefaultFormatExtension()
Returns the default extension of the format.- Specified by:
getDefaultFormatExtension
in interfaceFileFormatHandler
- Returns:
- the default extension (without the dot!)
-
reset
protected void reset()
Resets the writer (but does not clear the input data!). Derived classes must call this method in set-methods of parameters to assure the invalidation of previously generated data.- Overrides:
reset
in classAbstractOptionHandler
-
defineOptions
public void defineOptions()
Adds options to the internal list of options.- Specified by:
defineOptions
in interfaceOptionHandler
- Overrides:
defineOptions
in classAbstractOptionHandler
-
setOutput
public void setOutput(PlaceholderFile value)
Sets the file/directory to write to.- Specified by:
setOutput
in interfaceReportWriter<T extends Report>
- Parameters:
value
- the file/directory to write to
-
getOutput
public PlaceholderFile getOutput()
The file/directory to write to.- Specified by:
getOutput
in interfaceReportWriter<T extends Report>
- Returns:
- the file/directory to write to
-
outputTipText
public String outputTipText()
Returns the tip text for this property.- Specified by:
outputTipText
in interfaceReportWriter<T extends Report>
- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
write
public boolean write(T data)
Performs checks and writes the data.- Specified by:
write
in interfaceReportWriter<T extends Report>
- Parameters:
data
- the data to write- Returns:
- true if successfully written
-
checkData
protected void checkData(T data)
The default implementation only checks whether the provided file is an actual file and whether it exists (if m_OutputIsFile is TRUE). Otherwise the directory has to exist.- Parameters:
data
- the data to write
-
writeData
protected abstract boolean writeData(T data)
Performs the actual writing.- Parameters:
data
- the data to write- Returns:
- true if successfully written
-
cleanUp
public void cleanUp()
Can be used to free up memory. Default implementation just calls reset() and sets the chromatogram to null. Derived classes can add additional code.- Specified by:
cleanUp
in interfaceCleanUpHandler
- See Also:
reset()
-
destroy
public void destroy()
Frees up memory in a "destructive" non-reversible way.
Calls cleanUp() and cleans up the options.- Specified by:
destroy
in interfaceDestroyable
- Overrides:
destroy
in classAbstractOptionHandler
- See Also:
AbstractOptionHandler.cleanUpOptions()
-
compareTo
public int compareTo(Object o)
Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
Only compares the commandlines of the two objects.- Specified by:
compareTo
in interfaceComparable<T extends Report>
- Parameters:
o
- the object to be compared.- Returns:
- a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
- Throws:
ClassCastException
- if the specified object's type prevents it from being compared to this object.
-
equals
public boolean equals(Object o)
Returns whether the two objects are the same.
Only compares the commandlines of the two objects.
-
shallowCopy
public AbstractReportWriter shallowCopy()
Returns a shallow copy of itself, i.e., based on the commandline options.- Specified by:
shallowCopy
in interfaceShallowCopySupporter<T extends Report>
- Returns:
- the shallow copy
-
shallowCopy
public AbstractReportWriter shallowCopy(boolean expand)
Returns a shallow copy of itself, i.e., based on the commandline options.- Specified by:
shallowCopy
in interfaceShallowCopySupporter<T extends Report>
- Parameters:
expand
- whether to expand variables to their current values- Returns:
- the shallow copy
-
getWriters
public static String[] getWriters()
Returns a list with classnames of writers.- Returns:
- the writer classnames
-
forName
public static AbstractReportWriter forName(String classname, String[] options)
Instantiates the chromatogram writer with the given options.- Parameters:
classname
- the classname of the writer to instantiateoptions
- the options for the writer- Returns:
- the instantiated writer or null if an error occurred
-
forCommandLine
public static AbstractReportWriter forCommandLine(String cmdline)
Instantiates the chromatogram writer from the given commandline (i.e., classname and optional options).- Parameters:
cmdline
- the classname (and optional options) of the writer to instantiate- Returns:
- the instantiated writer or null if an error occurred
-
-