org.pf.text
Class ObjectIdGenerator

java.lang.Object
  extended by org.pf.text.ObjectIdGenerator
All Implemented Interfaces:
IObjectIdGenerator
Direct Known Subclasses:
ObjectIdentifierGenerator

public class ObjectIdGenerator
extends java.lang.Object
implements IObjectIdGenerator

Generates numeric IDs that are left padded with zeros.

Version:
1.0
Author:
M.Duchrow

Constructor Summary
ObjectIdGenerator()
          Initialize the new instance with default values.
ObjectIdGenerator(int idLength)
          Initialize the new instance with the length for the generated identifiers.
ObjectIdGenerator(long startId, int idLength)
          Initialize the new instance with the length for the generated identifiers and the id to start with.
 
Method Summary
 int getLength()
          Returns the length to which the IDs are filled up
 char getPadChar()
          Return the character that is used to fill up the IDs to the full length.
 java.lang.String getPrefix()
          Returns the prefix that will be prepended to every generated ID.
 java.lang.String newIdentifier()
          Returns a new unique identifier as string.
 long nextIdentifier()
          Returns a new identifier which is different to the last one.
 void setLength(int newValue)
          Set the length to which the IDs must be filled up with leading zeroes.
 void setPadChar(char fillChar)
          Set the character that is used to fill up the IDs to the full length.
 void setPrefix(java.lang.String newValue)
          Set the prefix that will be prepended to every generated ID.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectIdGenerator

public ObjectIdGenerator()
Initialize the new instance with default values. That is an ID length of 10 and a start ID of 1 with fill character '0'.


ObjectIdGenerator

public ObjectIdGenerator(int idLength)
Initialize the new instance with the length for the generated identifiers.

Parameters:
idLength - The length to which Ids are filled up with leading zeros (must be > 0)

ObjectIdGenerator

public ObjectIdGenerator(long startId,
                         int idLength)
Initialize the new instance with the length for the generated identifiers and the id to start with.

Parameters:
startId - The first id to be generated
idLength - The length to which Ids are filled up with leading zeros
Method Detail

newIdentifier

public java.lang.String newIdentifier()
Returns a new unique identifier as string.

Specified by:
newIdentifier in interface IObjectIdGenerator

nextIdentifier

public long nextIdentifier()
Returns a new identifier which is different to the last one.


getLength

public int getLength()
Returns the length to which the IDs are filled up


setLength

public void setLength(int newValue)
Set the length to which the IDs must be filled up with leading zeroes. Since all IDs are based on data type long a value greater than 20 is not really reasonable, however it is allowed here.

Parameters:
newValue - The length (must be > 0)

setPadChar

public void setPadChar(char fillChar)
Set the character that is used to fill up the IDs to the full length.

Parameters:
fillChar - The fill character

getPadChar

public char getPadChar()
Return the character that is used to fill up the IDs to the full length.


getPrefix

public java.lang.String getPrefix()
Returns the prefix that will be prepended to every generated ID.


setPrefix

public void setPrefix(java.lang.String newValue)
Set the prefix that will be prepended to every generated ID.