com.github.cage.token
Class RandomCharacterGeneratorFactory

java.lang.Object
  extended by com.github.cage.token.RandomCharacterGeneratorFactory
All Implemented Interfaces:
IGenerator<IGenerator<Character>>, IGeneratorFactory<Character>

public class RandomCharacterGeneratorFactory
extends Object
implements IGeneratorFactory<Character>

Factory that can generate Character generating IGenerators.

Author:
akiraly

Nested Class Summary
 class RandomCharacterGeneratorFactory.RandomCharacterGenerator
          Generates characters based on the settings of the factory.
 
Field Summary
static char[] ARABIC_NUMERALS
          Arabic numeral character array.
static char[] DEFAULT_DEFAULT_CHARACTER_SET
          Default character set for the default case.
static Map<Character,char[]> DEFAULT_SPECIAL_CHARACTER_SETS
          Special character sets for the default case.
static char[] ENGLISH_CONSONANTS
          English lower cased consonant character array.
static char[] ENGLISH_VOWELS
          English lower cased vowel character array.
 
Constructor Summary
RandomCharacterGeneratorFactory()
          Constructor.
RandomCharacterGeneratorFactory(char[] defaultCharacterSet, Map<Character,char[]> specialCharacterSets, Random rnd)
          Constructor.
RandomCharacterGeneratorFactory(Random rnd)
          Constructor.
 
Method Summary
protected static Map<Character,char[]> createDefaultSpecialCharacterSets()
          Helper function to build DEFAULT_SPECIAL_CHARACTER_SETS.
 char[] getDefaultCharacterSet()
           
 Map<Character,char[]> getSpecialCharacterSets()
           
 IGenerator<Character> 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

ENGLISH_VOWELS

public static final char[] ENGLISH_VOWELS
English lower cased vowel character array.


ENGLISH_CONSONANTS

public static final char[] ENGLISH_CONSONANTS
English lower cased consonant character array.


ARABIC_NUMERALS

public static final char[] ARABIC_NUMERALS
Arabic numeral character array.


DEFAULT_DEFAULT_CHARACTER_SET

public static final char[] DEFAULT_DEFAULT_CHARACTER_SET
Default character set for the default case. It contains the English lower cased letters.


DEFAULT_SPECIAL_CHARACTER_SETS

public static final Map<Character,char[]> DEFAULT_SPECIAL_CHARACTER_SETS
Special character sets for the default case.

Constructor Detail

RandomCharacterGeneratorFactory

public RandomCharacterGeneratorFactory()
Constructor.


RandomCharacterGeneratorFactory

public RandomCharacterGeneratorFactory(Random rnd)
Constructor.

Parameters:
rnd - used to generate random numbers. Can be null.

RandomCharacterGeneratorFactory

public RandomCharacterGeneratorFactory(char[] defaultCharacterSet,
                                       Map<Character,char[]> specialCharacterSets,
                                       Random rnd)
Constructor.

Parameters:
defaultCharacterSet - used generally for character choosing, can be null.
specialCharacterSets - map contains special cases. A (k, v) pair in this map means that character k can only be immediately followed by a character in v array. No value should be empty or null. The map parameter itself can be null.
rnd - used to generate random numbers. Can be null.
Method Detail

createDefaultSpecialCharacterSets

protected static Map<Character,char[]> createDefaultSpecialCharacterSets()
Helper function to build DEFAULT_SPECIAL_CHARACTER_SETS. It contains some rules to avoid confusing character pairs. Also makes sure that vowels and consonants follow each other in an alternating fashion.

Returns:
populated map

next

public IGenerator<Character> 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<IGenerator<Character>>
Returns:
generated object

getDefaultCharacterSet

public char[] getDefaultCharacterSet()
Returns:
default character set for character generation, not null

getSpecialCharacterSets

public Map<Character,char[]> getSpecialCharacterSets()
Returns:
map holding the special rules for each character, can be null


Copyright © 2011. All Rights Reserved.