2.17.2: 2011-06-17

net.sf.basedb.util.bfs
Class AbstractFilenameGenerator<T>

java.lang.Object
  extended by 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 (Tue, 12 Jan 2010) $

Field Summary
private  Set<String> generatedFiles
           
 
Constructor Summary
protected AbstractFilenameGenerator()
           
 
Method Summary
protected  boolean addFilename(String filename)
          Add the file name to the list of already generated file names.
protected  boolean isUnique(String filename)
          Checks if the suggested file name has already been generated by this file name generator or not.
protected  String makeUnique(String filename)
          Make sure that a file name is unique.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sf.basedb.util.bfs.FilenameGenerator
getNextFilename
 

Field Detail

generatedFiles

private Set<String> generatedFiles
Constructor Detail

AbstractFilenameGenerator

protected AbstractFilenameGenerator()
Method Detail

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

2.17.2: 2011-06-17