Class AbstractFileParser<T>

java.lang.Object
be.gaudry.model.file.AbstractFileParser<T>
Type Parameters:
T -
All Implemented Interfaces:
PropertyChangeListener, EventListener
Direct Known Subclasses:
FileChartCountParser, FileChartExtensionParser, FileChartModDateParser, FileChartSizeParser, ImagesDirectoryHighMemoryParser, ImagesDirectoryParser, MReportParser, RefreshSynchroParser, Runtastic2GpxParser, SearchFilesParser, SearchMediaParser, SimpleRenameParser, TransfertPhotosParser

public abstract class AbstractFileParser<T> extends Object implements PropertyChangeListener
An abstract class to parse files, forces to implement something to do on files (lengthy GUI-interacting tasks) in a dedicated thread threw an AbstractBrolWorker. \n As a new instance of AbstractBrolWorker must be created each time we want to perform a task, the new instance will be given to the parse(AbstractBrolWorker) method. \n Provided by the broldev.core.model project.
Since:
1.0 Jun 10, 2008, broldev.core.model 0.0.1-SNAPSHOT dependency
Version:
1.1 Feb 18, 2009
Author:
Steph GAUDRY
  • Field Details

    • validPreviousProgress

      protected boolean validPreviousProgress
      true if the maximum value has been calculated for the same kind of parsing. If a parse modification is done in the child class, we need setting this to false re-calculation of maximum value.
  • Constructor Details

    • AbstractFileParser

      public AbstractFileParser()
  • Method Details

    • finalize

      protected void finalize() throws Throwable
      Overrides:
      finalize in class Object
      Throws:
      Throwable
    • init

      protected void init()
      Override this to do some initializations before starting the parsing, like reset errors, etc.
    • togglePause

      public void togglePause()
      Enable pause if not enabled; disable it if enabled
    • isPauseProcessing

      public boolean isPauseProcessing()
      Returns:
      true if the process is in pause mode
    • propertyChange

      public void propertyChange(PropertyChangeEvent evt)
      Specified by:
      propertyChange in interface PropertyChangeListener
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
      See Also:
      equals(Object)
    • equals

      public boolean equals(Object o)
      Checks equality on following points : Some points are not checked :
      Overrides:
      equals in class Object
      See Also:
      Object.equals(java.lang.Object), hashCode()
    • parse

      public long parse(AbstractBrolWorker<T> bgw)
      Parses files from the defined start path, and call the performOnFile(AbstractBrolWorker, File, int, int) on each file.
      Parameters:
      bgw -
      Returns:
      the size of the matching files, not the size of the parsed directory
    • performOnFile

      protected abstract boolean performOnFile(AbstractBrolWorker<T> bgw, File file, int percent, int subDirDeep)
      Do something on each file
      Parameters:
      bgw - AbstractBrolWorker to perform cancel if needed, and report progress
      file - file to check
      percent - Progress percentage
      subDirDeep - Deep of the directory in comparison with start directory
      Returns:
      true if we must stop the parsing of current directory (ie. if we have a vob file, we don't check the other files in this directory) false otherwise
    • performOnDirectory

      protected void performOnDirectory(AbstractBrolWorker<T> bgw, File directory, int subDirDeep)
      Do something on each directory. Does nothing in this default implementation, but may be overrided.
      Parameters:
      bgw - AbstractBrolWorker to notify progress.
      directory - File object. No need to check if is directory (already done in the parser)
      subDirDeep - Deep of the directory in comparison with start directory
      Since:
      0.1.12-SNAPSHOT (Feb 8 2009)
    • setLanguage

      public void setLanguage()
      Localize some strings using the LanguageHelper features. See the logging information to know how the logging is implemented.
      Since:
      1.1 (Feb 18, 2009)
    • parseFiles

      protected void parseFiles(AbstractBrolWorker<T> bgw, File file, int subDirDeep)
      Does the real parsing job. Recursive method if the isIncludeSubFolders() is true. See the logging information to know how the logging is implemented.
      Parameters:
      bgw - SearchFilesWorker to perform cancel if needed, and report progress
      file - to get size
      subDirDeep - Deep of the directory in comparison with start directory
    • isIncludeSubFolders

      public boolean isIncludeSubFolders()
      Returns:
      true if sub-folders must be parsed
    • setIncludeSubFolders

      public void setIncludeSubFolders(boolean includeSubFolders)
      True to search on the sub folders. Modifying this value forces total size calculation if progress needed
      Parameters:
      includeSubFolders - the includeSubFolders to set
    • isIncludeHiddenFiles

      public boolean isIncludeHiddenFiles()
      Returns:
      true if the hidden files must be parsed
    • setIncludeHiddenFiles

      public void setIncludeHiddenFiles(boolean includeHidden)
      True to search on the hidden files. Modifying this forces total size calculation if progress needed
      Parameters:
      includeHidden - the includeHidden to set
    • isPreCalcProgress

      public boolean isPreCalcProgress()
      Returns:
      true if the maximum value must be calculated before parsing files
    • setPreCalcProgress

      public void setPreCalcProgress(boolean preCalcProgress)
      Parameters:
      preCalcProgress - true if the maximum value must be calculated before parsing files
    • getStartPath

      public String getStartPath()
      Returns:
      the startPath
    • setStartPath

      public void setStartPath(String startPath)
      Path of the root directory where to search Modifying this forces total size calculation if progress needed
      Parameters:
      startPath - the startPath to set
    • getProgressMax

      public long getProgressMax()
      The returned value is not the size of the parsed directory, but only the total size of the matched files. \n To get the total size of a directory, call the FileUtils.getFileSizeString(File) method.
      Returns:
      total length of matching files
    • isPreCalculated

      public boolean isPreCalculated()
      Any modification on the parsing configuration wich affects the progress percentage will set this to false
      Returns:
      true if the maximum value has been calculated for the same kind of parsing