things.common.tools
Class TokenFactory

java.lang.Object
  extended by things.common.tools.Gamer
      extended by things.common.tools.TokenFactory

public class TokenFactory
extends Gamer

A set of tools for creating tokens.

Version:
1.0

Version History

 EPG - Initial, integrated from another project. - 26 NOV 04
EPG - Converted to use Gamer and added methods. - 11 AUG 06
Author:
Erich P. Gatejen

Field Summary
static char[] alphaCharacters
           
static char[] alphaNumericCharacters
           
static char[] alphaNumericCharactersLower
           
static char[] alphaNumericCharactersS
           
static char[] hexCharactersLower
           
static int MAX_SETS
          The max sets allowed.
static int MIN_SIZE
          Smallest token possible.
static char[] numericCharacters
           
 
Fields inherited from class things.common.tools.Gamer
rng
 
Constructor Summary
TokenFactory(int maxSize, boolean highASCII, boolean lowASCII)
          Construct the factory.
 
Method Summary
 char randomACharacter()
          Get a random alpha character.
 java.lang.String randomHex()
          Random hex token of random size.
 java.lang.String randomHex(int size)
          Random hex token of a specific size.
 java.lang.String randomHexSets(int sets)
          Random hex token of specified sets.
 char randomNCharacter()
          Get a random numeric character.
 java.lang.String randomToken()
          Get a random token of random size.
 java.lang.String randomToken(int size)
          Get a random token of specified size.
 FlaggedString randomToken822(int spacePercentage, int specialPecentage, int quotablePercentage)
          Get a random, flagged token appropriate for rfc822 fields (such as mail addresses) of specfied size.
 FlaggedString randomToken822(int size, int spacePercentage, int specialPercentage, int quotablePercentage)
          Get a random, flagged token appropriate for rfc822 fields (such as mail addresses) of specfied size.
 java.lang.String randomTokenAN()
          Get a random alphanumeric token of random size.
 java.lang.String randomTokenAN(int size)
          Random alphanumeric token of a specific size.
 java.lang.String randomTokenANS()
          Random alphanumeric token of random size with a chance of spaces and a few benign punctuation.
 java.lang.String randomTokenANS(int size)
          Random alphanumeric token of random size with a chance of spaces and a few benign punctuation of a specific size.
 java.lang.String randomTokenANSets(int sets)
          Random alphanumeric token of specified sets.
 java.lang.String randomTokenBASE64(int size)
          Create a random token of specified size with only valid BASE64 characters.
 java.lang.String randomTokenDNS()
          Create a random token of random size with only valid DNS characters.
 java.lang.String randomTokenDNS(int size)
          Create a random token of specified size with only valid DNS characters.
 java.lang.String randomTokenN()
          Get a random numeric token of random size.
 java.lang.String randomTokenN(int size)
          Random numeric token of a specific size.
 java.lang.String sentence(int maxWords, int wordPercentChance, int maxSize)
          A sentence of randomly generated fake words.
 
Methods inherited from class things.common.tools.Gamer
flipcoin, percent, pick, pickNumber, range
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_SETS

public static final int MAX_SETS
The max sets allowed.

See Also:
Constant Field Values

MIN_SIZE

public static final int MIN_SIZE
Smallest token possible.

See Also:
Constant Field Values

alphaCharacters

public static final char[] alphaCharacters

numericCharacters

public static final char[] numericCharacters

alphaNumericCharacters

public static final char[] alphaNumericCharacters

alphaNumericCharactersS

public static final char[] alphaNumericCharactersS

alphaNumericCharactersLower

public static final char[] alphaNumericCharactersLower

hexCharactersLower

public static final char[] hexCharactersLower
Constructor Detail

TokenFactory

public TokenFactory(int maxSize,
                    boolean highASCII,
                    boolean lowASCII)
Construct the factory.

Parameters:
maxSize - maximum size of the token, must be at least 3. The minimum size is automatically 2.
highASCII - if true, it will include chars over 127
lowASCII - if true, it will include chars between 1 and 32 (inclusive)
Method Detail

randomToken

public java.lang.String randomToken()
Get a random token of random size. It will abide by the construction configuration.

Returns:
the token.

randomToken

public java.lang.String randomToken(int size)
Get a random token of specified size. It will abide by the construction configuration.

Parameters:
size - the size. If less than 1, it'll return an empty token. It will ignore the maxSize specified at construction.
Returns:
the token.

randomTokenAN

public java.lang.String randomTokenAN()
Get a random alphanumeric token of random size.

Returns:
the token.

randomTokenAN

public java.lang.String randomTokenAN(int size)
Random alphanumeric token of a specific size.

Parameters:
size - the size. If less than 1, it'll return an empty token. It will ignore the maxSize specified at construction.
Returns:
the token.

randomTokenN

public java.lang.String randomTokenN()
Get a random numeric token of random size.

Returns:
the token.

randomTokenN

public java.lang.String randomTokenN(int size)
Random numeric token of a specific size.

Parameters:
size - the size. If less than 1, it'll return an empty token. It will ignore the maxSize specified at construction.
Returns:
the token.

randomTokenANS

public java.lang.String randomTokenANS()
Random alphanumeric token of random size with a chance of spaces and a few benign punctuation.

Returns:
the token.

randomTokenANS

public java.lang.String randomTokenANS(int size)
Random alphanumeric token of random size with a chance of spaces and a few benign punctuation of a specific size.

Parameters:
size - the size. If less than 1, it'll return an empty token. It will ignore the maxSize specified at construction.
Returns:
the token.

randomTokenANSets

public java.lang.String randomTokenANSets(int sets)
Random alphanumeric token of specified sets. The sets # of tokens will be concatenated into one token.

Parameters:
sets - the number of sets. If it is less than one or greater than MAX_SETS, it'll treat it as 1.
Returns:
the token.

randomHex

public java.lang.String randomHex()
Random hex token of random size.

Returns:
the token.

randomHex

public java.lang.String randomHex(int size)
Random hex token of a specific size.

Parameters:
size - the size. If less than 1, it'll return an empty token. It will ignore the maxSize specified at construction.
Returns:
the token.

randomHexSets

public java.lang.String randomHexSets(int sets)
Random hex token of specified sets. The sets # of tokens will be concatenated into one token.

Parameters:
sets - the number of sets. If it is less than one or greater than MAX_SETS, it'll treat it as 1.
Returns:
the token.

randomToken822

public FlaggedString randomToken822(int spacePercentage,
                                    int specialPecentage,
                                    int quotablePercentage)
Get a random, flagged token appropriate for rfc822 fields (such as mail addresses) of specfied size.

Parameters:
spacePercentage - the percent chance for character that it'll be a space character.
specialPecentage - the percent chance for character that it'll be a 822 'special' character.
quotablePercentage - the percent chance for character that it'll be a 822 'quotable' character (besides spaces).
Returns:
a flagged string. Be sure to quote it in an address if hasWhiteSpace() or hasQuotable() is true.

randomToken822

public FlaggedString randomToken822(int size,
                                    int spacePercentage,
                                    int specialPercentage,
                                    int quotablePercentage)
Get a random, flagged token appropriate for rfc822 fields (such as mail addresses) of specfied size.

Parameters:
spacePercentage - the percent chance for character that it'll be a space character.
specialPercentage - the percent chance for character that it'll be a 822 'special' character.
quotablePercentage - the percent chance for character that it'll be a 822 'quotable' character (besides spaces).
Returns:
a flagged string. Be sure to quote it in an address if hasWhiteSpace() or hasQuotable() is true.

randomTokenDNS

public java.lang.String randomTokenDNS()
Create a random token of random size with only valid DNS characters.

Returns:
the token as a string

randomTokenDNS

public java.lang.String randomTokenDNS(int size)
Create a random token of specified size with only valid DNS characters.

Parameters:
size - the size. If less than 1, it'll return an empty token. It will ignore the maxSize specified at construction.
Returns:
the token as a string

randomTokenBASE64

public java.lang.String randomTokenBASE64(int size)
Create a random token of specified size with only valid BASE64 characters.

Parameters:
size - the size. If less than 1, it'll return an empty token. It will ignore the maxSize specified at construction.
Returns:
the token as a string

sentence

public java.lang.String sentence(int maxWords,
                                 int wordPercentChance,
                                 int maxSize)
A sentence of randomly generated fake words.

Parameters:
maxWords - absolute max words
wordPercentChance - percent chance after each word that we'll do another word.
maxSize - maximum total size.
Returns:
the sentence.

randomACharacter

public char randomACharacter()
Get a random alpha character.

Returns:
the character.

randomNCharacter

public char randomNCharacter()
Get a random numeric character.

Returns:
the character.


Things.