public class ObjectIdGenerator extends java.lang.Object implements IObjectIdGenerator, StringGenerator
Modifier and Type | Field and Description |
---|---|
protected int |
bufferLen |
protected static int |
DEFAULT_LENGTH |
protected static char |
DEFAULT_PAD_CHAR |
protected static long |
DEFAULT_START_ID |
Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
protected void |
calcBufferLength() |
java.lang.String |
generateString()
Returns a new string.
|
java.lang.String |
generateString(int len)
Generates a new string (i.e.
|
protected int |
getDefaultLength() |
protected char |
getDefaultPadChar() |
protected long |
getDefaultStartId() |
int |
getFullLength()
Returns the full length of the generated identifiers.
|
int |
getLength()
Returns the length to which the IDs (the numeric part without prefix))
are filled up (left padded).
|
protected long |
getNextAvailableId() |
protected long |
getNextId() |
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.
|
protected int |
getPrefixLength() |
boolean |
hasPrefix()
Returns whether or not a prefix is defined.
|
protected java.lang.String |
leftPad(long 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 len)
Set the length to which the IDs (numeric part without prefix) must be
filled-up with the defined padding character.
|
protected void |
setNextAvailableId(long newValue) |
protected void |
setNextId(long id) |
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.
|
protected StringUtil |
str() |
protected static final char DEFAULT_PAD_CHAR
protected static final long DEFAULT_START_ID
protected static final int DEFAULT_LENGTH
protected int bufferLen
public ObjectIdGenerator()
public ObjectIdGenerator(int idLength)
idLength
- The length to which Ids are filled up with leading zeros (must be > 0)public ObjectIdGenerator(long startId, int idLength)
startId
- The first id to be generatedidLength
- The length to which Ids are filled up with leading zerosprotected long getNextAvailableId()
protected void setNextAvailableId(long newValue)
public java.lang.String newIdentifier()
newIdentifier
in interface IObjectIdGenerator
public long nextIdentifier()
public int getFullLength()
getPrefix()
,
getLength()
public int getLength()
public void setLength(int len)
len
- The new length (must be > 0).getPadChar()
,
setPadChar(char)
public void setPadChar(char fillChar)
fillChar
- The fill characterpublic char getPadChar()
public java.lang.String getPrefix()
public void setPrefix(java.lang.String newValue)
public boolean hasPrefix()
public java.lang.String generateString()
newIdentifier()
.generateString
in interface StringGenerator
public java.lang.String generateString(int len)
The specified length will be used only for this single string generation.
That is, the defined length (see getLength()
and setLength(int)
)
of this object will not be used or changed by this method.
generateString
in interface StringGenerator
len
- The length of the string to generate.java.lang.IllegalArgumentException
- if the given length is negative.protected int getPrefixLength()
protected java.lang.String leftPad(long id)
protected long getNextId()
protected void setNextId(long id)
protected void calcBufferLength()
protected long getDefaultStartId()
protected int getDefaultLength()
protected char getDefaultPadChar()
protected StringUtil str()