Package adams.data.io.input
Class AbstractReportReader<T extends Report>
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.core.logging.CustomLoggingLevelObject
-
- adams.core.option.AbstractOptionHandler
-
- adams.data.io.input.AbstractReportReader<T>
-
- Type Parameters:
T- the type of report
- All Implemented Interfaces:
CleanUpHandler,Destroyable,GlobalInfoSupporter,FileFormatHandler,LoggingLevelHandler,LoggingSupporter,OptionHandler,ShallowCopySupporter<AbstractReportReader>,SizeOfHandler,Stoppable,StoppableWithFeedback,ReportReader<T>,Serializable,Comparable
- Direct Known Subclasses:
AbstractSimpleCSVReportReader,AbstractSimpleJsonReportReader,AbstractSimpleReportReader,CocoAnnotationsReportReader,DeepLabCutCSVReader,DetectronAnnotationsReportReader,ImageClassificationGridSpreadSheetReader,ImageClassificationJsonReportReader,ImageClassificationSpreadSheetReportReader,ObjectLocationsSpreadSheetReader,OpexObjectLocationsReader,PascalVOCObjectLocationsReader,VggXmlAnnotationReportReader,ViaAnnotationsReportReader,YoloAnnotationsReportReader
public abstract class AbstractReportReader<T extends Report> extends AbstractOptionHandler implements Comparable, CleanUpHandler, ReportReader<T>, ShallowCopySupporter<AbstractReportReader>, StoppableWithFeedback, FileFormatHandler
Abstract ancestor for readers that read files in various formats and creates a reports.- Version:
- $Revision$
- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected PlaceholderFilem_Inputthe file to parse.protected booleanm_Stoppedwhether the reader got stopped.-
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 AbstractReportReader()
-
Method Summary
All Methods Static 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.voiddefineOptions()Adds options to the internal list of options.voiddestroy()Frees up memory in a "destructive" non-reversible way.protected abstract intdetermineParentID(Report report)Tries to determine the parent ID for the current report.booleanequals(Object o)Returns whether the two objects are the same.static AbstractReportReaderforCommandLine(String cmdline)Instantiates the report reader from the given commandline (i.e., classname and optional options).static AbstractReportReaderforName(String classname, String[] options)Instantiates the report reader with the given options.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.static String[]getReaders()Returns a list with classnames of readers.StringinputTipText()Returns the tip text for this property.booleanisStopped()Whether the execution has been stopped.abstract TnewInstance()Returns a new instance of the report class in use.protected voidpostRead(List<T> data)Post-processing after reading the data.List<T>read()Performs checks and (always) reads the data.protected abstract List<T>readData()Performs the actual reading.protected voidreset()Resets the reader.voidsetInput(PlaceholderFile value)Sets the file/directory to read.AbstractReportReadershallowCopy()Returns a shallow copy of itself, i.e., based on the commandline options.AbstractReportReadershallowCopy(boolean expand)Returns a shallow copy of itself, i.e., based on the commandline options.voidstopExecution()Stops the execution.-
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_Input
protected PlaceholderFile m_Input
the file to parse.
-
m_Stopped
protected boolean m_Stopped
whether the reader got stopped.
-
-
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!)
-
reset
protected void reset()
Resets the reader. 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
-
setInput
public void setInput(PlaceholderFile value)
Sets the file/directory to read.- Specified by:
setInputin interfaceReportReader<T extends Report>- Parameters:
value- the file/directory to read
-
getInput
public PlaceholderFile getInput()
The file/directory to read.- Specified by:
getInputin interfaceReportReader<T extends Report>- Returns:
- the file/directory to read
-
inputTipText
public String inputTipText()
Returns the tip text for this property.- Specified by:
inputTipTextin interfaceReportReader<T extends Report>- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
read
public List<T> read()
Performs checks and (always) reads the data.- Specified by:
readin interfaceReportReader<T extends Report>- Returns:
- the report loaded 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.
-
readData
protected abstract List<T> readData()
Performs the actual reading.- Returns:
- the reports that were read
-
postRead
protected void postRead(List<T> data)
Post-processing after reading the data.- Parameters:
data- the reports to post-process
-
stopExecution
public void stopExecution()
Stops the execution.- Specified by:
stopExecutionin interfaceStoppable
-
isStopped
public boolean isStopped()
Whether the execution has been stopped.- Specified by:
isStoppedin interfaceStoppableWithFeedback- Returns:
- true if stopped
-
determineParentID
protected abstract int determineParentID(Report report)
Tries to determine the parent ID for the current report.- Parameters:
report- the report to determine the ID for- Returns:
- the parent database ID, -1 if it cannot be determined
-
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()
-
newInstance
public abstract T newInstance()
Returns a new instance of the report class in use.- Returns:
- the new (empty) report
-
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 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 AbstractReportReader shallowCopy()
Returns a shallow copy of itself, i.e., based on the commandline options.- Specified by:
shallowCopyin interfaceShallowCopySupporter<T extends Report>- Returns:
- the shallow copy
-
shallowCopy
public AbstractReportReader shallowCopy(boolean expand)
Returns a shallow copy of itself, i.e., based on the commandline options.- Specified by:
shallowCopyin interfaceShallowCopySupporter<T extends Report>- Parameters:
expand- whether to expand variables to their current values- Returns:
- the shallow copy
-
getReaders
public static String[] getReaders()
Returns a list with classnames of readers.- Returns:
- the reader classnames
-
forName
public static AbstractReportReader forName(String classname, String[] options)
Instantiates the report reader with the given options.- Parameters:
classname- the classname of the reader to instantiateoptions- the options for the reader- Returns:
- the instantiated reader or null if an error occurred
-
forCommandLine
public static AbstractReportReader forCommandLine(String cmdline)
Instantiates the report reader from the given commandline (i.e., classname and optional options).- Parameters:
cmdline- the classname (and optional options) of the reader to instantiate- Returns:
- the instantiated reader or null if an error occurred
-
-