public class RandomIdentifierGenerationStrategy extends java.lang.Object implements IdentifierGenerationStrategy
Random source and encodes them into a string using a
BinaryEncoder (Hex by default).| Modifier and Type | Field and Description |
|---|---|
private org.apache.commons.codec.BinaryEncoder |
encoder
Encoder used to convert the random bytes in to a string.
|
private java.util.Random |
random
Random number generator.
|
private int |
sizeOfIdentifier
Number of random bytes in the identifier.
|
| Constructor and Description |
|---|
RandomIdentifierGenerationStrategy()
Constructor.
|
RandomIdentifierGenerationStrategy(int identifierSize)
Constructor.
|
RandomIdentifierGenerationStrategy(java.util.Random source,
int identifierSize,
org.apache.commons.codec.BinaryEncoder identifierEncoder)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
generateIdentifier()
Generates an identifier guaranteed to be XML ID safe.
|
java.lang.String |
generateIdentifier(boolean xmlSafe)
Generates an identifier.
|
private final java.util.Random random
private final int sizeOfIdentifier
private final org.apache.commons.codec.BinaryEncoder encoder
public RandomIdentifierGenerationStrategy()
SecureRandom, size of identifier is set to 16
bytes, and the encoder is set to a Hex.public RandomIdentifierGenerationStrategy(int identifierSize)
SecureRandom and the encoder is set to a
Hex.identifierSize - number of random bytes in identifierpublic RandomIdentifierGenerationStrategy(@Nonnull
java.util.Random source,
int identifierSize,
@Nonnull
org.apache.commons.codec.BinaryEncoder identifierEncoder)
source - source of random bytesidentifierSize - number of random bytes in the identifieridentifierEncoder - encoder used to convert random bytes to string identifier@Nonnull public java.lang.String generateIdentifier()
generateIdentifier in interface IdentifierGenerationStrategypublic java.lang.String generateIdentifier(boolean xmlSafe)
generateIdentifier in interface IdentifierGenerationStrategyxmlSafe - true iff the result must be XML ID safe