Package net.sf.basedb.util.bfs
Class AbstractFilenameGenerator<T>
java.lang.Object
net.sf.basedb.util.bfs.AbstractFilenameGenerator<T>
- All Implemented Interfaces:
FilenameGenerator<T>
- Direct Known Subclasses:
SuggestedFilenameGenerator
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 Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
addFilename
(String filename) Add the file name to the list of already generated file names.protected boolean
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 Details
-
generatedFiles
-
-
Constructor Details
-
AbstractFilenameGenerator
protected AbstractFilenameGenerator()
-
-
Method Details
-
isUnique
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
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
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
-