org.databene.benerator.factory
Class GeneratorFactory

java.lang.Object
  extended by org.databene.benerator.factory.GeneratorFactory

public class GeneratorFactory
extends java.lang.Object

Provides factory methods for generators.

Created: 23.08.2006 21:44:27

Since:
0.1
Author:
Volker Bergmann

Method Summary
static
<T> Generator<T>
createFromWeightedLiteralList(java.lang.String valueSpec, java.lang.Class<T> targetType, Distribution distribution, boolean unique)
           
static
<T> Generator<T[]>
getArrayGenerator(java.lang.Class<T> componentType, Generator<T>... sources)
          Creates a generator that reads products of an array of generators and combines them to an array.
static
<T> Generator<T[]>
getArrayGenerator(Generator<T> source, java.lang.Class<T> type, int minSize, int maxSize, Distribution sizeDistribution)
          Creates a generator that combines several products of a source generator to a collection.
static Generator<java.lang.Boolean> getBooleanGenerator(double trueQuota)
          Creates a generator for boolean values with a trueQuota [0-1]
static Generator<java.lang.Character> getCharacterGenerator(java.lang.Character... characters)
          Creates a character generator that creates values from a set of characters
static Generator<java.lang.Character> getCharacterGenerator(java.util.Collection<java.lang.Character> characters)
          Creates a character generator that creates values from a collection of characters
static Generator<java.lang.Character> getCharacterGenerator(java.lang.String pattern, java.util.Locale locale)
          Creates a Character generator that creates characters of a Locale which match a regular expression.
static
<C extends java.util.Collection<I>,I>
Generator<C>
getCollectionGenerator(java.lang.Class<C> collectionType, Generator<I> source, int minSize, int maxSize, Distribution sizeDistribution)
          Creates a generator that combines several products of a source generator to a collection.
static
<T> Generator<T>
getConstantGenerator(T value)
          Creates a generator that returns a constant value.
static
<S,T> Generator<T>
getConvertingGenerator(Generator<S> source, org.databene.commons.Converter<S,T> converter)
          Creates a generator that accepts products from a source generator and converts them to target products by the converter
static Generator<java.lang.String> getCSVCellGenerator(java.lang.String uri, char separator, boolean cyclic)
          Creates a generator that iterates through the cells of a CSV file.
static Generator<java.lang.String[]> getCSVLineGenerator(java.lang.String uri, char separator, boolean ignoreEmptyLines, boolean cyclic)
          Creates a generator that creates lines from a CSV file as String arrays.
static Generator<java.util.Date> getDateGenerator(java.util.Date min, java.util.Date max, long precision, Distribution distribution)
          Creates a Date generator that generates random dates.
static Generator<java.util.Date> getDateGenerator(java.lang.String uri, java.lang.String encoding, java.lang.String pattern)
          Creates a date generator that generates date entries from a CSV file.
static Generator<java.lang.String> getMessageGenerator(java.lang.String pattern, int minLength, int maxLength, Generator... sources)
          Creates a generator that generates messages by reading the products of several source generators and combining them by a Java MessageFormat.
static
<T extends java.lang.Number>
Generator<T>
getNumberGenerator(java.lang.Class<T> numberType, T min, T max, int totalDigits, int fractionDigits, T precision, Distribution distribution, boolean unique)
          Creates a generator for numbers.
static
<T extends java.lang.Number>
Generator<T>
getNumberGenerator(java.lang.Class<T> numberType, T min, T max, T precision, Distribution distribution, boolean unique)
          Creates a generator for numbers.
static Generator<java.lang.String> getRegexStringGenerator(java.lang.String pattern, int minLength, java.lang.Integer maxLength, boolean unique)
          Creates a generator that produces Strings which match a regular expression in a locale
static
<T> Generator<T>
getSampleGenerator(java.lang.Class<T> generatedType, java.util.Collection<T> values)
          Creates a Generator that chooses from a set of values with equal weights.
static
<T> Generator<T>
getSampleGenerator(java.lang.Class<T> generatedType, T... values)
          Creates a Generator that chooses from an array of values with equal weights.
static
<T> Generator<T>
getSampleGenerator(java.util.Collection<T> values)
          Creates a Generator that chooses from a set of values with equal weights.
static
<T> Generator<T>
getSampleGenerator(java.lang.String uri, java.lang.String encoding, org.databene.commons.Converter<java.lang.String,T> converter)
          Creates a generator that reads cell Strings from a CSV file and converts them into objects by a converter
static
<T> Generator<T>
getSampleGenerator(T... values)
          Creates a Generator that chooses from an array of values with equal weights.
static Generator<java.lang.String> getTextLineGenerator(java.lang.String uri, boolean cyclic)
          Creates a generator that iterates through the lines of a text file.
static Generator<java.lang.Character> getUniqueCharacterGenerator(java.lang.String pattern, java.util.Locale locale)
           
static
<T> Generator<T>
getWeightedSampleGenerator(java.util.Collection<WeightedSample<T>> samples)
          Creates a generator that chooses from a set of samples, using an individual weight for each sample.
static
<T> Generator<T>
getWeightedSampleGenerator(WeightedSample<T>... samples)
          Creates a generator that chooses from a set of samples, using an individual weight for each sample.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getBooleanGenerator

public static Generator<java.lang.Boolean> getBooleanGenerator(double trueQuota)
Creates a generator for boolean values with a trueQuota [0-1]

Parameters:
trueQuota - a value from 0 to 1, indicating the quota of true values to generate among the non-null values
Returns:
a Boolean generator of the desired characteristics

getNumberGenerator

public static <T extends java.lang.Number> Generator<T> getNumberGenerator(java.lang.Class<T> numberType,
                                                                           T min,
                                                                           T max,
                                                                           T precision,
                                                                           Distribution distribution,
                                                                           boolean unique)
Creates a generator for numbers.

Parameters:
numberType - the number type, e.g. java.lang.Integer
min - the minimum number to generate
max - the maximum number to generate
precision - the resolution to use in number generation.
distribution - The Sequence of WeightFunction to use for generation
Returns:
a Number generator of the desired characteristics

getNumberGenerator

public static <T extends java.lang.Number> Generator<T> getNumberGenerator(java.lang.Class<T> numberType,
                                                                           T min,
                                                                           T max,
                                                                           int totalDigits,
                                                                           int fractionDigits,
                                                                           T precision,
                                                                           Distribution distribution,
                                                                           boolean unique)
Creates a generator for numbers.

Parameters:
numberType - the number type, e.g. java.lang.Integer
min - the minimum number to generate
max - the maximum number to generate
precision - the resolution to use in number generation.
Returns:
a Number generator of the desired characteristics

createFromWeightedLiteralList

public static <T> Generator<T> createFromWeightedLiteralList(java.lang.String valueSpec,
                                                             java.lang.Class<T> targetType,
                                                             Distribution distribution,
                                                             boolean unique)

getSampleGenerator

public static <T> Generator<T> getSampleGenerator(java.lang.String uri,
                                                  java.lang.String encoding,
                                                  org.databene.commons.Converter<java.lang.String,T> converter)
Creates a generator that reads cell Strings from a CSV file and converts them into objects by a converter

Parameters:
uri - The URI or filename to read the data from
converter - the converter to use for representing the file entries
Returns:
a Generator that creates instances of the parameterized type T.

getSampleGenerator

public static <T> Generator<T> getSampleGenerator(java.util.Collection<T> values)
Creates a Generator that chooses from a set of values with equal weights.

Parameters:
values - A collection of values to choose from
Returns:
a generator that selects from the listed sample values

getSampleGenerator

public static <T> Generator<T> getSampleGenerator(java.lang.Class<T> generatedType,
                                                  java.util.Collection<T> values)
Creates a Generator that chooses from a set of values with equal weights.

Parameters:
values - A collection of values to choose from
Returns:
a generator that selects from the listed sample values

getSampleGenerator

public static <T> Generator<T> getSampleGenerator(T... values)
Creates a Generator that chooses from an array of values with equal weights.

Parameters:
values - An array of values to choose from
Returns:
a generator that selects from the listed sample values

getSampleGenerator

public static <T> Generator<T> getSampleGenerator(java.lang.Class<T> generatedType,
                                                  T... values)
Creates a Generator that chooses from an array of values with equal weights.

Parameters:
values - An array of values to choose from
Returns:
a generator that selects from the listed sample values

getWeightedSampleGenerator

public static <T> Generator<T> getWeightedSampleGenerator(java.util.Collection<WeightedSample<T>> samples)
Creates a generator that chooses from a set of samples, using an individual weight for each sample.

Parameters:
samples - A collection of sample values
Returns:
a generator of the desired characteristics

getWeightedSampleGenerator

public static <T> Generator<T> getWeightedSampleGenerator(WeightedSample<T>... samples)
Creates a generator that chooses from a set of samples, using an individual weight for each sample.

Parameters:
samples - A collection of sample values
Returns:
a generator of the desired characteristics

getDateGenerator

public static Generator<java.util.Date> getDateGenerator(java.util.Date min,
                                                         java.util.Date max,
                                                         long precision,
                                                         Distribution distribution)
Creates a Date generator that generates random dates.

Parameters:
min - The earliest Date to generate
max - The latest Date to generate
precision - the time resolution of dates in milliseconds
distribution - the distribution to use
Returns:
a generator of the desired characteristics

getDateGenerator

public static Generator<java.util.Date> getDateGenerator(java.lang.String uri,
                                                         java.lang.String encoding,
                                                         java.lang.String pattern)
Creates a date generator that generates date entries from a CSV file.

Parameters:
uri - the uri of the CSV file.
pattern - the pattern to use for parsing the CSV cells
Returns:
a generator of the desired characteristics

getCharacterGenerator

public static Generator<java.lang.Character> getCharacterGenerator(java.lang.String pattern,
                                                                   java.util.Locale locale)
Creates a Character generator that creates characters of a Locale which match a regular expression.

Parameters:
pattern - the regular expression that indicates the available range of values. If null, any letters of the specified locale will be used
locale - the locale to use for '\w' evaluation
Returns:
a generator of the desired characteristics

getUniqueCharacterGenerator

public static Generator<java.lang.Character> getUniqueCharacterGenerator(java.lang.String pattern,
                                                                         java.util.Locale locale)

getCharacterGenerator

public static Generator<java.lang.Character> getCharacterGenerator(java.util.Collection<java.lang.Character> characters)
Creates a character generator that creates values from a collection of characters

Parameters:
characters - the set of characters to choose from
Returns:
a generator of the desired characteristics

getCharacterGenerator

public static Generator<java.lang.Character> getCharacterGenerator(java.lang.Character... characters)
Creates a character generator that creates values from a set of characters

Parameters:
characters - the set of characters to choose from
Returns:
a generator of the desired characteristics

getRegexStringGenerator

public static Generator<java.lang.String> getRegexStringGenerator(java.lang.String pattern,
                                                                  int minLength,
                                                                  java.lang.Integer maxLength,
                                                                  boolean unique)
                                                           throws org.databene.commons.ConfigurationError
Creates a generator that produces Strings which match a regular expression in a locale

Parameters:
pattern - the regular expression
minLength - the minimum length of the products
maxLength - the maximum length of the products
Returns:
a generator of the desired characteristics
Throws:
org.databene.commons.ConfigurationError

getConvertingGenerator

public static <S,T> Generator<T> getConvertingGenerator(Generator<S> source,
                                                        org.databene.commons.Converter<S,T> converter)
Creates a generator that accepts products from a source generator and converts them to target products by the converter

Parameters:
source - the source generator
converter - the converter to apply to the products of the source generator
Returns:
a generator of the desired characteristics

getMessageGenerator

public static Generator<java.lang.String> getMessageGenerator(java.lang.String pattern,
                                                              int minLength,
                                                              int maxLength,
                                                              Generator... sources)
Creates a generator that generates messages by reading the products of several source generators and combining them by a Java MessageFormat.

Parameters:
pattern - the MessageFormat pattern
minLength - the minimum length of the generated value
maxLength - the maximum length of the generated value
sources - the source generators of which to assemble the products
Returns:
a generator of the desired characteristics
See Also:
MessageFormat

getCollectionGenerator

public static <C extends java.util.Collection<I>,I> Generator<C> getCollectionGenerator(java.lang.Class<C> collectionType,
                                                                                        Generator<I> source,
                                                                                        int minSize,
                                                                                        int maxSize,
                                                                                        Distribution sizeDistribution)
Creates a generator that combines several products of a source generator to a collection.

Parameters:
collectionType - the type of collection to create, e.g. java.util.List or java.util.TreeSet
source - the generator that provides the collection items
sizeDistribution - distribution for the collection size
Returns:
a generator of the desired characteristics

getArrayGenerator

public static <T> Generator<T[]> getArrayGenerator(Generator<T> source,
                                                   java.lang.Class<T> type,
                                                   int minSize,
                                                   int maxSize,
                                                   Distribution sizeDistribution)
Creates a generator that combines several products of a source generator to a collection.

Parameters:
source - the generator that provides the array items
type - the type of the array
sizeDistribution - distribution for the array length
Returns:
a generator of the desired characteristics

getArrayGenerator

public static <T> Generator<T[]> getArrayGenerator(java.lang.Class<T> componentType,
                                                   Generator<T>... sources)
Creates a generator that reads products of an array of generators and combines them to an array.

Parameters:
sources - the source generators
Returns:
a generator of the desired characteristics

getConstantGenerator

public static <T> Generator<T> getConstantGenerator(T value)
Creates a generator that returns a constant value.

Parameters:
value - the value to return
Returns:
a generator that returns a constant value.

getCSVCellGenerator

public static Generator<java.lang.String> getCSVCellGenerator(java.lang.String uri,
                                                              char separator,
                                                              boolean cyclic)
Creates a generator that iterates through the cells of a CSV file.

Parameters:
uri - the uri of the CSV file
separator - the cell separator used in the CSV file
cyclic - indicates wether iteration should restart from the first line after it reaches the file end.
Returns:
a generator of the desired characteristics

getCSVLineGenerator

public static Generator<java.lang.String[]> getCSVLineGenerator(java.lang.String uri,
                                                                char separator,
                                                                boolean ignoreEmptyLines,
                                                                boolean cyclic)
Creates a generator that creates lines from a CSV file as String arrays.

Parameters:
uri - the uri of the CSV file
separator - the cell separator used in the CSV file
ignoreEmptyLines - flag wether to leave out empty lines
cyclic - indicates wether iteration should restart from the first line after it reaches the file end.
Returns:
a generator of the desired characteristics

getTextLineGenerator

public static Generator<java.lang.String> getTextLineGenerator(java.lang.String uri,
                                                               boolean cyclic)
Creates a generator that iterates through the lines of a text file.

Parameters:
uri - the uri of the text file
cyclic - indicates wether iteration should restart from the first line after it reaches the file end.
Returns:
a generator of the desired characteristics


Copyright © 2011. All Rights Reserved.