public class RandomStringGenerator extends java.lang.Object implements StringGenerator
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_LENGTH
The default length (10) being used if not specified differently.
|
Constructor and Description |
---|
RandomStringGenerator()
Creates a generator with all default values set (length=10, chars=[A-Z,a-z,0-9]).
|
RandomStringGenerator(int defaultLength)
Creates a generator with all default values set (length=10, chars=[A-Z,a-z,0-9]).
|
RandomStringGenerator(java.util.Random random)
Creates a generator with all default values set (length=10, chars=[A-Z,a-z,0-9])
and a custom randomizer.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
generateString()
Generates a new string.
|
java.lang.String |
generateString(int length)
Generates a new string with the specified length.
|
java.lang.String |
getAllowedCharacters()
Returns the set of characters that are used as base for the string generation.
|
protected char[] |
getAllowedCharsArray() |
int |
getDefaultLength() |
protected java.util.Random |
getRandom() |
protected java.lang.Object |
nextChar() |
protected int |
nextIndex() |
void |
setAllowedCharacters(java.lang.String allowedChars)
Sets the set of characters that are used as base for the string generation.
|
protected void |
setAllowedCharsArray(char[] charArray) |
void |
setDefaultLength(int length)
Sets the length to be used as default for generating new strings.
|
public static final int DEFAULT_LENGTH
public RandomStringGenerator()
public RandomStringGenerator(int defaultLength)
public RandomStringGenerator(java.util.Random random)
public java.lang.String generateString(int length)
StringGenerator
generateString
in interface StringGenerator
length
- The length of the string to generate.public java.lang.String generateString()
StringGenerator
generateString
in interface StringGenerator
public int getDefaultLength()
public void setDefaultLength(int length)
length
- The new length value which must be positive.java.lang.IllegalArgumentException
- If the given length is not positive.public java.lang.String getAllowedCharacters()
public void setAllowedCharacters(java.lang.String allowedChars)
allowedChars
- A string containing all characters that are possible in
generated strings (must not be null).java.lang.IllegalArgumentException
- If the given string is null.protected java.lang.Object nextChar()
protected int nextIndex()
protected java.util.Random getRandom()
protected char[] getAllowedCharsArray()
protected void setAllowedCharsArray(char[] charArray)