Class AbstractFilenameGenerator<T>

java.lang.Object
net.sf.basedb.util.bfs.AbstractFilenameGenerator<T>
All Implemented Interfaces:
FilenameGenerator<T>
Direct Known Subclasses:
SuggestedFilenameGenerator

public abstract class AbstractFilenameGenerator<T> extends Object implements FilenameGenerator<T>
Abstract superclass for file names generator implementions that will help with ensuring that a generator creates unique file names. Subclasses may simply call makeUnique(String) to ensure that no duplicate file names are generated.
Version:
2.15
Author:
Nicklas
Last modified
$Date: 2010-01-12 14:21:49 +0100 (ti, 12 jan 2010) $
  • Field Details

    • generatedFiles

      private Set<String> generatedFiles
  • Constructor Details

    • AbstractFilenameGenerator

      protected AbstractFilenameGenerator()
  • Method Details

    • isUnique

      protected boolean isUnique(String filename)
      Checks if the suggested file name has already been generated by this file name generator or not.
      Parameters:
      filename - The filename to check
      Returns:
      TRUE if the name is unique or FALSE if it has already been used
    • addFilename

      protected boolean addFilename(String filename)
      Add the file name to the list of already generated file names.
      Parameters:
      filename - The file name to add
      Returns:
      TRUE if the file name has not been used before, FALSE otherwise
    • makeUnique

      protected String makeUnique(String filename)
      Make sure that a file name is unique. If the suggested file name is already unique the input parameter is returned. Otherwise a new filename is generated by appending a counter value to it until a unique name is found. The counter value is added before any extension. Eg. example.txt, example-2.txt, example-3.txt would be generated if this method was called with "example.txt" as a parameter three times. The returned filename is automatically added to the list of known generated file names.
      Parameters:
      filename - The file name to check
      Returns:
      A file name that is sure to be unique