Package adams.data.io.output
Class AbstractDataContainerWriter<T extends DataContainer>
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.core.logging.CustomLoggingLevelObject
-
- adams.core.option.AbstractOptionHandler
-
- adams.data.io.output.AbstractDataContainerWriter<T>
-
- Type Parameters:
T- the type of data to handle
- All Implemented Interfaces:
AdditionalInformationHandler,CleanUpHandler,Destroyable,GlobalInfoSupporter,FileFormatHandler,LoggingLevelHandler,LoggingSupporter,OptionHandler,ShallowCopySupporter<DataContainerWriter>,SizeOfHandler,DataContainerWriter<T>,Serializable,Comparable
- Direct Known Subclasses:
AbstractTimeseriesWriter,DataContainerToByteArray.DummyWriter,DataContainerToString.DummyWriter
public abstract class AbstractDataContainerWriter<T extends DataContainer> extends AbstractOptionHandler implements DataContainerWriter<T>
Abstract ancestor for writers that write data containers 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 PlaceholderFilem_Outputthe file to write to.protected booleanm_OutputIsFileindicates whether the output has to be a file (= default) or directory.-
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 AbstractDataContainerWriter()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract booleancanWriteMultiple()Returns whether writing of multiple containers is supported.protected voidcheckData(List<T> data)The default implementation only checks whether the provided file is an actual file and whether it exists (if m_OutputIsFile is TRUE).voidcleanUp()Can be used to free up memory.intcompareTo(Object o)Compares this object with the specified object for order.voiddefineOptions()Adds options to the internal list of options.voiddestroy()Frees up memory in a "destructive" non-reversible way.booleanequals(Object o)Returns whether the two objects are the same.static DataContainerWriterforCommandLine(String cmdline)Instantiates the spectrum writer from the given commandline (i.e., classname and optional options).static DataContainerWriterforName(String classname, String[] options)Instantiates the spectrum writer with the given options.StringgetAdditionalInformation()Returns the additional information.StringgetDefaultFormatExtension()Returns the default extension of the format.abstract StringgetFormatDescription()Returns a string describing the format (used in the file chooser).abstract String[]getFormatExtensions()Returns the extension(s) of the format.PlaceholderFilegetOutput()The file/directory to write to.static String[]getWriters()Returns a list with classnames of writers.booleanisOutputFile()Returns whether the output needs to be a file or directory.StringoutputTipText()Returns the tip text for this property.protected voidreset()Resets the writer (but does not clear the input data!).voidsetOutput(PlaceholderFile value)Sets the file/directory to write to.DataContainerWritershallowCopy()Returns a shallow copy of itself, i.e., based on the commandline options.DataContainerWritershallowCopy(boolean expand)Returns a shallow copy of itself, i.e., based on the commandline options.booleanwrite(List<T> data)Performs checks and writes the data.booleanwrite(T data)Performs checks and writes the data.protected abstract booleanwriteData(List<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
-
Methods inherited from interface adams.core.option.OptionHandler
cleanUpOptions, getOptionManager, toCommandLine
-
-
-
-
Field Detail
-
m_Output
protected PlaceholderFile m_Output
the file to write to.
-
m_OutputIsFile
protected boolean m_OutputIsFile
indicates whether the output has to be a file (= default) or directory.
-
-
Method Detail
-
getFormatDescription
public abstract String getFormatDescription()
Returns a string describing the format (used in the file chooser).- Specified by:
getFormatDescriptionin interfaceFileFormatHandler- Returns:
- a description suitable for displaying in the file chooser
-
getFormatExtensions
public abstract String[] getFormatExtensions()
Returns the extension(s) of the format.- Specified by:
getFormatExtensionsin interfaceFileFormatHandler- Returns:
- the extension(s) (without the dot!)
-
getDefaultFormatExtension
public String getDefaultFormatExtension()
Returns the default extension of the format.- Specified by:
getDefaultFormatExtensionin interfaceFileFormatHandler- Returns:
- the default extension (without the dot!)
-
getAdditionalInformation
public String getAdditionalInformation()
Returns the additional information.- Specified by:
getAdditionalInformationin interfaceAdditionalInformationHandler- Returns:
- the additional information, null or 0-length string for no information
-
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:
resetin classAbstractOptionHandler
-
defineOptions
public void defineOptions()
Adds options to the internal list of options.- Specified by:
defineOptionsin interfaceOptionHandler- Overrides:
defineOptionsin classAbstractOptionHandler
-
isOutputFile
public boolean isOutputFile()
Returns whether the output needs to be a file or directory.- Specified by:
isOutputFilein interfaceDataContainerWriter<T extends DataContainer>- Returns:
- true if the output needs to be a file, a directory otherwise
-
setOutput
public void setOutput(PlaceholderFile value)
Sets the file/directory to write to.- Specified by:
setOutputin interfaceDataContainerWriter<T extends DataContainer>- Parameters:
value- the file/directory to write to
-
getOutput
public PlaceholderFile getOutput()
The file/directory to write to.- Specified by:
getOutputin interfaceDataContainerWriter<T extends DataContainer>- Returns:
- the file/directory to write to
-
outputTipText
public String outputTipText()
Returns the tip text for this property.- Specified by:
outputTipTextin interfaceDataContainerWriter<T extends DataContainer>- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
canWriteMultiple
public abstract boolean canWriteMultiple()
Returns whether writing of multiple containers is supported.- Specified by:
canWriteMultiplein interfaceDataContainerWriter<T extends DataContainer>- Returns:
- true if multiple containers are supported
-
write
public boolean write(T data)
Performs checks and writes the data.- Specified by:
writein interfaceDataContainerWriter<T extends DataContainer>- Parameters:
data- the data to write- Returns:
- true if successfully written
- See Also:
write(List)
-
write
public boolean write(List<T> data)
Performs checks and writes the data.- Specified by:
writein interfaceDataContainerWriter<T extends DataContainer>- Parameters:
data- the data to write- Returns:
- true if successfully written
-
checkData
protected void checkData(List<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(List<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 spectrum to null. Derived classes can add additional code.- Specified by:
cleanUpin 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:
destroyin interfaceDestroyable- Overrides:
destroyin 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:
compareToin interfaceComparable<T extends DataContainer>- 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 DataContainerWriter shallowCopy()
Returns a shallow copy of itself, i.e., based on the commandline options.- Specified by:
shallowCopyin interfaceShallowCopySupporter<T extends DataContainer>- Returns:
- the shallow copy
-
shallowCopy
public DataContainerWriter shallowCopy(boolean expand)
Returns a shallow copy of itself, i.e., based on the commandline options.- Specified by:
shallowCopyin interfaceShallowCopySupporter<T extends DataContainer>- 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 DataContainerWriter forName(String classname, String[] options)
Instantiates the spectrum 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 DataContainerWriter forCommandLine(String cmdline)
Instantiates the spectrum 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
-
-