public class ObjectIdGenerator extends java.lang.Object implements IObjectIdGenerator, StringGenerator
Modifier and Type | Field and Description |
---|---|
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 |
---|---|
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 |
getNextId()
Returns the next identifier value without incrementing.
|
protected java.util.concurrent.atomic.AtomicLong |
getNextIdHolder() |
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 |
hasPadding()
Returns whether or not padding for the identifiers is activated.
|
boolean |
hasPrefix()
Returns whether or not a prefix is defined.
|
protected java.lang.String |
leftPad(long id) |
protected java.lang.String |
leftPad(long id,
int stringLength) |
java.lang.String |
newIdentifier()
Returns a new unique identifier as string.
|
long |
nextIdentifier()
Returns a new identifier which is different to the last one
and automatically increments the internal value for the next id.
|
void |
setLength(int len)
Sets the length to which the IDs (numeric part without prefix) must be
filled-up with the defined padding character.
|
protected void |
setNextId(long id)
Sets the next identifier to the given value.
|
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
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 zerospublic java.lang.String newIdentifier()
newIdentifier
in interface IObjectIdGenerator
public long nextIdentifier()
public boolean hasPadding()
public int getFullLength()
getPrefix()
,
getLength()
public int getLength()
public void setLength(int len)
len
- The new length. If len <= 0 no padding will be done!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 java.lang.String leftPad(long id, int stringLength)
protected long getNextId()
protected void setNextId(long id)
protected long getDefaultStartId()
protected int getDefaultLength()
protected char getDefaultPadChar()
protected java.util.concurrent.atomic.AtomicLong getNextIdHolder()
protected StringUtil str()