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<DataContainerReader>,SizeOfHandler,DataContainerReader<T>,Serializable,Comparable
- Direct Known Subclasses:
AbstractTimeseriesReader,ByteArrayToDataContainer.DummyReader,InstanceReader,StringToDataContainer.DummyReader
public abstract class AbstractDataContainerReader<T extends DataContainer> extends AbstractOptionHandler implements DataContainerReader<T>
Abstract ancestor for readers that read files in various formats and turn them into data containers.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected booleanm_CreateDummyReportwhether to create a dumy report if none is present.protected PlaceholderFilem_Inputthe file to parse.protected booleanm_InputIsFileindicates whether the input has to be a file (= default) or directory.protected booleanm_Processedindicates whether the data has been processed.protected List<T>m_ReadDatathe 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 voidcheckData()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.voidcleanUp()Can be used to free up memory.intcompareTo(Object o)Compares this object with the specified object for order.protected ReportcreateDummyReport(T cont)Creates a dummy report.StringcreateDummyReportTipText()Returns the tip text for this property.voiddefineOptions()Adds options to the internal list of options.voiddestroy()Frees up memory in a "destructive" non-reversible way.protected List<T>doRead()Performs checks and (always) reads the data.booleanequals(Object o)Returns whether the two objects are the same.StringgetAdditionalInformation()Returns the additional information.booleangetCreateDummyReport()Returns whether to create a dummy report if none present.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.PlaceholderFilegetInput()The file/directory to read.protected voidinitialize()Initializes the members.StringinputTipText()Returns the tip text for this property.booleanisInputFile()Returns whether the input needs to be a file or directory.protected voidpostProcessData()For performing post-processing.List<T>read()Returns the data containers generated from the file.protected abstract voidreadData()Performs the actual reading.protected voidreset()Resets the reader (but does not clear the input data!).voidsetCreateDummyReport(boolean value)Sets whether to create a dummy report if none present.voidsetInput(PlaceholderFile value)Sets the file/directory to read.DataContainerReadershallowCopy()Returns a shallow copy of itself, i.e., based on the commandline options.DataContainerReadershallowCopy(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
-
Methods inherited from interface adams.core.option.OptionHandler
cleanUpOptions, getOptionManager, toCommandLine
-
-
-
-
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:
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 (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
-
initialize
protected void initialize()
Initializes the members.- Overrides:
initializein 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:
resetin classAbstractOptionHandler
-
defineOptions
public void defineOptions()
Adds options to the internal list of options.- Specified by:
defineOptionsin interfaceOptionHandler- Overrides:
defineOptionsin classAbstractOptionHandler
-
isInputFile
public boolean isInputFile()
Returns whether the input needs to be a file or directory.- Specified by:
isInputFilein interfaceDataContainerReader<T extends DataContainer>- 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.- Specified by:
setInputin interfaceDataContainerReader<T extends DataContainer>- Parameters:
value- the file/directory to read
-
getInput
public PlaceholderFile getInput()
The file/directory to read.- Specified by:
getInputin interfaceDataContainerReader<T extends DataContainer>- Returns:
- the file/directory to read
-
inputTipText
public String inputTipText()
Returns the tip text for this property.- Specified by:
inputTipTextin interfaceDataContainerReader<T extends DataContainer>- 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.- Specified by:
setCreateDummyReportin interfaceDataContainerReader<T extends DataContainer>- 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.- Specified by:
getCreateDummyReportin interfaceDataContainerReader<T extends DataContainer>- Returns:
- true if a dummy report is generated if necessary
-
createDummyReportTipText
public String createDummyReportTipText()
Returns the tip text for this property.- Specified by:
createDummyReportTipTextin interfaceDataContainerReader<T extends DataContainer>- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
read
public List<T> read()
Returns the data containers generated from the file. If necessary, performs the parsing (e.g., if not yet read).- Specified by:
readin interfaceDataContainerReader<T extends DataContainer>- Returns:
- the data containers generated from the file
-
doRead
protected List<T> doRead()
Performs checks and (always) reads the data.- Returns:
- the data containers 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(T)
-
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:
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 DataContainerReader 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 DataContainerReader 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
-
-