com.github.cage.token
Class RandomTokenGenerator

java.lang.Object
  extended by com.github.cage.token.RandomTokenGenerator
All Implemented Interfaces:
IGenerator<String>

public class RandomTokenGenerator
extends Object
implements IGenerator<String>

A simple random String generator that can be used to generate tokens for the captcha images. In its default mode instances of this class generate words from English lower cased letters where vowels and consonants are alternating.

Author:
akiraly

Field Summary
protected static int DEFAULT_TOKEN_LEN_DELTA
          Default maximum length of token is DEFAULT_TOKEN_LEN_MIN + 2.
protected static int DEFAULT_TOKEN_LEN_MIN
          Default minimum length of token.
 
Constructor Summary
RandomTokenGenerator()
          Constructor.
RandomTokenGenerator(Random rnd)
          Constructor.
RandomTokenGenerator(Random rnd, IGeneratorFactory<Character> characterGeneratorFactory, int minLength, int delta)
          Constructor.
RandomTokenGenerator(Random rnd, int length)
          Constructor.
RandomTokenGenerator(Random rnd, int minLength, int delta)
          Constructor.
 
Method Summary
 IGeneratorFactory<Character> getCharacterGeneratorFactory()
           
 int getDelta()
           
 int getMinLength()
           
 String next()
          Returns an object with type T on every call.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_TOKEN_LEN_MIN

protected static final int DEFAULT_TOKEN_LEN_MIN
Default minimum length of token.

See Also:
Constant Field Values

DEFAULT_TOKEN_LEN_DELTA

protected static final int DEFAULT_TOKEN_LEN_DELTA
Default maximum length of token is DEFAULT_TOKEN_LEN_MIN + 2.

See Also:
Constant Field Values
Constructor Detail

RandomTokenGenerator

public RandomTokenGenerator()
Constructor.


RandomTokenGenerator

public RandomTokenGenerator(Random rnd)
Constructor.

Parameters:
rnd - random generator to be used, can be null

RandomTokenGenerator

public RandomTokenGenerator(Random rnd,
                            int length)
Constructor.

Parameters:
length - the length of the generated words, must be > 0
rnd - random generator to be used, can be null

RandomTokenGenerator

public RandomTokenGenerator(Random rnd,
                            int minLength,
                            int delta)
Constructor.

Parameters:
rnd - random generator to be used, can be null
minLength - the minimum length of the generated words, must be > 0
delta - minLength + delta is the maximum length of the generated words, delta must be >= 0

RandomTokenGenerator

public RandomTokenGenerator(Random rnd,
                            IGeneratorFactory<Character> characterGeneratorFactory,
                            int minLength,
                            int delta)
Constructor.

Parameters:
rnd - random generator to be used, can be null
characterGeneratorFactory - character generator factory to be used for the actual character creation, can be null
minLength - the minimum length of the generated words, must be > 0
delta - minLength + delta is the maximum length of the generated words, delta must be >= 0
Method Detail

next

public String next()
Description copied from interface: IGenerator
Returns an object with type T on every call. The returned object does not have to be a new instance.

Specified by:
next in interface IGenerator<String>
Returns:
generated object

getCharacterGeneratorFactory

public IGeneratorFactory<Character> getCharacterGeneratorFactory()
Returns:
character generator factory used by this class, not null

getMinLength

public int getMinLength()
Returns:
minimum length of generated tokens

getDelta

public int getDelta()
Returns:
maximum length difference to add to the minimum length


Copyright © 2011. All Rights Reserved.