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<AbstractDataContainerWriter>
,SizeOfHandler
,Serializable
,Comparable
- Direct Known Subclasses:
AbstractTimeseriesWriter
public abstract class AbstractDataContainerWriter<T extends DataContainer> extends AbstractOptionHandler implements Comparable, CleanUpHandler, ShallowCopySupporter<AbstractDataContainerWriter>, FileFormatHandler, AdditionalInformationHandler
Abstract ancestor for writers that write data containers to files in various formats.- Version:
- $Revision$
- 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.protected boolean
m_OutputIsFile
indicates 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 boolean
canWriteMultiple()
Returns whether writing of multiple containers is supported.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).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 AbstractDataContainerWriter
forCommandLine(String cmdline)
Instantiates the spectrum writer from the given commandline (i.e., classname and optional options).static AbstractDataContainerWriter
forName(String classname, String[] options)
Instantiates the spectrum writer with the given options.String
getAdditionalInformation()
Returns the additional information.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(s) of the format.PlaceholderFile
getOutput()
The file/directory to write to.static String[]
getWriters()
Returns a list with classnames of writers.boolean
isOutputFile()
Returns whether the output needs to be a file or directory.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.AbstractDataContainerWriter
shallowCopy()
Returns a shallow copy of itself, i.e., based on the commandline options.AbstractDataContainerWriter
shallowCopy(boolean expand)
Returns a shallow copy of itself, i.e., based on the commandline options.boolean
write(List<T> data)
Performs checks and writes the data.boolean
write(T data)
Performs checks and writes the data.protected abstract boolean
writeData(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
-
-
-
-
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:
getFormatDescription
in 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:
getFormatExtensions
in interfaceFileFormatHandler
- Returns:
- the extension(s) (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!)
-
getAdditionalInformation
public String getAdditionalInformation()
Returns the additional information.- Specified by:
getAdditionalInformation
in 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:
reset
in classAbstractOptionHandler
-
defineOptions
public void defineOptions()
Adds options to the internal list of options.- Specified by:
defineOptions
in interfaceOptionHandler
- Overrides:
defineOptions
in classAbstractOptionHandler
-
isOutputFile
public boolean isOutputFile()
Returns whether the output needs to be a file or directory.- 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.- Parameters:
value
- the file/directory to write to
-
getOutput
public PlaceholderFile getOutput()
The file/directory to write to.- Returns:
- the file/directory to write to
-
outputTipText
public String outputTipText()
Returns the tip text for this property.- 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.- Returns:
- true if multiple containers are supported
-
write
public boolean write(T data)
Performs checks and writes the data.- 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.- 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:
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 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 AbstractDataContainerWriter shallowCopy()
Returns a shallow copy of itself, i.e., based on the commandline options.- Specified by:
shallowCopy
in interfaceShallowCopySupporter<T extends DataContainer>
- Returns:
- the shallow copy
-
shallowCopy
public AbstractDataContainerWriter shallowCopy(boolean expand)
Returns a shallow copy of itself, i.e., based on the commandline options.- Specified by:
shallowCopy
in 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 AbstractDataContainerWriter 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 AbstractDataContainerWriter 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
-
-