|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.pfsw.text.RandomStringGenerator
public class RandomStringGenerator
A string generator that produces a new random string for each invocation. It can be configured regarding the string length and the allowed characters in the generated string.
| Field Summary | |
|---|---|
static int |
DEFAULT_LENGTH
The default length (10) being used if not specified differently. |
| Constructor Summary | |
|---|---|
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. |
|
| Method Summary | |
|---|---|
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. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int DEFAULT_LENGTH
| Constructor Detail |
|---|
public RandomStringGenerator()
public RandomStringGenerator(int defaultLength)
public RandomStringGenerator(java.util.Random random)
| Method Detail |
|---|
public java.lang.String generateString(int length)
StringGenerator
generateString in interface StringGeneratorlength - The length of the string to generate.
public java.lang.String generateString()
StringGenerator
generateString in interface StringGeneratorpublic 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)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||