2.17.2: 2011-06-17

net.sf.basedb.util.bfs
Class SequenceFilenameGenerator

java.lang.Object
  extended by net.sf.basedb.util.bfs.SequenceFilenameGenerator
All Implemented Interfaces:
FilenameGenerator<Object>

public class SequenceFilenameGenerator
extends Object
implements FilenameGenerator<Object>

File name generator implementation that generates file names using a simple numerical counter. It is possible to give a prexix and/or suffix. For example, with prefix="file-" and suffix=".txt", the following file sequence is generated: file-1.txt, file-2.txt, file-3.txt This generator completely ignores the owner and suggested file names.

Version:
2.15
Author:
Nicklas
Last modified
$Date: 2010-01-12 14:21:49 +0100 (Tue, 12 Jan 2010) $

Field Summary
private  int nextFileNum
           
private  String prefix
           
private  String suffix
           
 
Constructor Summary
SequenceFilenameGenerator()
          Create a new sequence file name generator.
SequenceFilenameGenerator(String prefix, String suffix, int firstFileNum)
          Create a new sequence file name generator.
 
Method Summary
 String getNextFilename(Object owner, String suggestedFilename)
          Get the next file name.
 int getNextFileNumber()
          Get the next file number.
 String getPrefix()
          Get the prefix that is used for file name generation.
 String getSuffix()
          Get the suffix that is used for file name generation.
 void setPrefix(String prefix)
          Set the prefix that is used for file name generation.
 void setSuffix(String suffix)
          Set the suffix that is used for file name generation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

prefix

private String prefix

suffix

private String suffix

nextFileNum

private int nextFileNum
Constructor Detail

SequenceFilenameGenerator

public SequenceFilenameGenerator()
Create a new sequence file name generator. No prefix or suffix are used and the sequence starts at 1.


SequenceFilenameGenerator

public SequenceFilenameGenerator(String prefix,
                                 String suffix,
                                 int firstFileNum)
Create a new sequence file name generator.

Parameters:
prefix - The prefix to use
suffix - The suffix to use
firstFileNum - The sequence number of the first file
Method Detail

getNextFilename

public String getNextFilename(Object owner,
                              String suggestedFilename)
Description copied from interface: FilenameGenerator
Get the next file name. This method should never return the same file name more than one time (given a single implementor instance). The generator implementation should not concern itself with the underlying file system or if the file already exists or not (this is a task for the DataWriterFactory implementation).

Specified by:
getNextFilename in interface FilenameGenerator<Object>
Parameters:
owner - The owner of the data in the file
suggestedFilename - A default suggested file name (can be null)
Returns:
A unique file name

getPrefix

public String getPrefix()
Get the prefix that is used for file name generation.

Returns:
The prefix or null if no prefix was given

setPrefix

public void setPrefix(String prefix)
Set the prefix that is used for file name generation.

Parameters:
prefix - The prefix or null to not use a prefix

getSuffix

public String getSuffix()
Get the suffix that is used for file name generation.

Returns:
The suffix or null if no suffix was given

setSuffix

public void setSuffix(String suffix)
Set the suffix that is used for file name generation.

Parameters:
suffix - The suffix or null to not use a suffix

getNextFileNumber

public int getNextFileNumber()
Get the next file number. This counter is increased for each file that is generated (eg. each time getNextFilename(Object, String) is called.


2.17.2: 2011-06-17