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 the given length and default characters ([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 |
---|---|
static RandomStringGenerator |
create()
Creates a generator with all default values set (length=10, chars=[A-Z,a-z,0-9]).
|
static RandomStringGenerator |
create(int defaultLength)
Creates a generator with the given length and default characters ([A-Z,a-z,0-9]).
|
static RandomStringGenerator |
create(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.
|
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() |
RandomStringGenerator |
setAllowedCharacters(java.lang.String allowedChars)
Sets the set of characters that are used as base for the string generation.
|
protected void |
setAllowedCharsArray(char[] charArray) |
RandomStringGenerator |
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 static RandomStringGenerator create()
public static RandomStringGenerator create(int defaultLength)
public static RandomStringGenerator create(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 RandomStringGenerator 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 RandomStringGenerator 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)