Package adams.data.io.input
Class AbstractDataContainerReader<T extends DataContainer>
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.core.logging.CustomLoggingLevelObject
-
- adams.core.option.AbstractOptionHandler
-
- adams.data.io.input.AbstractDataContainerReader<T>
-
- Type Parameters:
T
- the type of data to read
- All Implemented Interfaces:
AdditionalInformationHandler
,CleanUpHandler
,Destroyable
,GlobalInfoSupporter
,FileFormatHandler
,LoggingLevelHandler
,LoggingSupporter
,OptionHandler
,ShallowCopySupporter<AbstractDataContainerReader>
,SizeOfHandler
,Serializable
,Comparable
- Direct Known Subclasses:
AbstractTimeseriesReader
,InstanceReader
public abstract class AbstractDataContainerReader<T extends DataContainer> extends AbstractOptionHandler implements Comparable, CleanUpHandler, ShallowCopySupporter<AbstractDataContainerReader>, FileFormatHandler, AdditionalInformationHandler
Abstract ancestor for readers that read files in various formats and turn them into data containers.- Version:
- $Revision$
- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
m_CreateDummyReport
whether to create a dumy report if none is present.protected PlaceholderFile
m_Input
the file to parse.protected boolean
m_InputIsFile
indicates whether the input has to be a file (= default) or directory.protected boolean
m_Processed
indicates whether the data has been processed.protected List<T>
m_ReadData
the data containers that have been read.-
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 AbstractDataContainerReader()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
checkData()
The default implementation only checks whether the provided file object is an actual file and whether it exists (if m_InputIsFile = true), or if the file object is a directory and whether it exists.void
cleanUp()
Can be used to free up memory.int
compareTo(Object o)
Compares this object with the specified object for order.protected Report
createDummyReport(T cont)
Creates a dummy report.String
createDummyReportTipText()
Returns the tip text for this property.void
defineOptions()
Adds options to the internal list of options.void
destroy()
Frees up memory in a "destructive" non-reversible way.protected List<T>
doRead()
Performs checks and (always) reads the data.boolean
equals(Object o)
Returns whether the two objects are the same.String
getAdditionalInformation()
Returns the additional information.boolean
getCreateDummyReport()
Returns whether to create a dummy report if none present.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
getInput()
The file/directory to read.protected void
initialize()
Initializes the members.String
inputTipText()
Returns the tip text for this property.boolean
isInputFile()
Returns whether the input needs to be a file or directory.protected void
postProcessData()
For performing post-processing.List<T>
read()
Returns the spectrums generated from the file.protected abstract void
readData()
Performs the actual reading.protected void
reset()
Resets the reader (but does not clear the input data!).void
setCreateDummyReport(boolean value)
Sets whether to create a dummy report if none present.void
setInput(PlaceholderFile value)
Sets the file/directory to read.AbstractDataContainerReader
shallowCopy()
Returns a shallow copy of itself, i.e., based on the commandline options.AbstractDataContainerReader
shallowCopy(boolean expand)
Returns a shallow copy of itself, i.e., based on the commandline options.-
Methods inherited from class adams.core.option.AbstractOptionHandler
cleanUpOptions, finishInit, getDefaultLoggingLevel, getOptionManager, globalInfo, 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_Input
protected PlaceholderFile m_Input
the file to parse.
-
m_CreateDummyReport
protected boolean m_CreateDummyReport
whether to create a dumy report if none is present.
-
m_ReadData
protected List<T extends DataContainer> m_ReadData
the data containers that have been read.
-
m_Processed
protected boolean m_Processed
indicates whether the data has been processed.
-
m_InputIsFile
protected boolean m_InputIsFile
indicates whether the input 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 (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
-
initialize
protected void initialize()
Initializes the members.- Overrides:
initialize
in classAbstractOptionHandler
-
reset
protected void reset()
Resets the reader (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
-
isInputFile
public boolean isInputFile()
Returns whether the input needs to be a file or directory.- Returns:
- true if the input needs to be a file, a directory otherwise
-
setInput
public void setInput(PlaceholderFile value)
Sets the file/directory to read.- Parameters:
value
- the file/directory to read
-
getInput
public PlaceholderFile getInput()
The file/directory to read.- Returns:
- the file/directory to read
-
inputTipText
public String inputTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setCreateDummyReport
public void setCreateDummyReport(boolean value)
Sets whether to create a dummy report if none present.- Parameters:
value
- if true then a dummy report is generated if necessary
-
getCreateDummyReport
public boolean getCreateDummyReport()
Returns whether to create a dummy report if none present.- Returns:
- true if a dummy report is generated if necessary
-
createDummyReportTipText
public String createDummyReportTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
read
public List<T> read()
Returns the spectrums generated from the file. If necessary, performs the parsing (e.g., if not yet read).- Returns:
- the spectrums generated from the file
-
doRead
protected List<T> doRead()
Performs checks and (always) reads the data.- Returns:
- the spectrums generated from the file
-
checkData
protected void checkData()
The default implementation only checks whether the provided file object is an actual file and whether it exists (if m_InputIsFile = true), or if the file object is a directory and whether it exists.- See Also:
m_InputIsFile
-
readData
protected abstract void readData()
Performs the actual reading.
-
postProcessData
protected void postProcessData()
For performing post-processing.
Default implementation adds dummy reports.- See Also:
#createDummyReport()
-
createDummyReport
protected Report createDummyReport(T cont)
Creates a dummy report.
Default implementation returns null.- Parameters:
cont
- the data container the dummy is for- Returns:
- the dummy report or null
- See Also:
m_CreateDummyReport
,postProcessData()
-
cleanUp
public void cleanUp()
Can be used to free up memory. Default implementation just calls reset(). 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 AbstractDataContainerReader 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 AbstractDataContainerReader 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
-
-