public final class UUIDIdentityGenerator extends Object implements IdentityGenerator
Generated identities have the following form: (PREFIX_)UUID_COUNT.
PREFIX is optional, see UUIDIdentityGenerator(java.lang.String)
and UUIDIdentityGenerator(java.lang.String, int)
.
COUNT can be left-padded with zeroes, see UUIDIdentityGenerator(int)
and UUIDIdentityGenerator(java.lang.String, int)
.
Each instance holds a UUID
and an AtomicLong
based counter. Identities are generated by concatenating the UUID and the counter. The later is incremented along the way.
Constructor and Description |
---|
UUIDIdentityGenerator() |
UUIDIdentityGenerator(int countLength)
Use this constructor to left-pad counter with zeroes.
|
UUIDIdentityGenerator(String prefix)
Use this constructor to prefix the identities.
|
UUIDIdentityGenerator(String prefix, int countLength)
Use this constructor to prefix the identities and left-pad the counter with zeroes.
|
Modifier and Type | Method and Description |
---|---|
String |
newIdentity()
Generate a new identity.
|
void |
reset()
Reset the identity UUID & counter.
|
public UUIDIdentityGenerator()
public UUIDIdentityGenerator(int countLength)
countLength
- Length of the COUNT part of the generated identities. A negative value disable padding.
public UUIDIdentityGenerator(String prefix)
prefix
- String to prepend to all generated identities
public UUIDIdentityGenerator(String prefix, int countLength)
prefix
- String to prepend to all generated identities
countLength
- Length of the COUNT part of the generated identities. A negative value disable padding.
public String newIdentity()
IdentityGenerator
newIdentity
in interface
IdentityGenerator
public void reset()