org.databene.benerator.sample
Class SampleGenerator<E>

java.lang.Object
  extended by org.databene.benerator.util.AbstractGenerator<E>
      extended by org.databene.benerator.util.ThreadSafeGenerator<E>
          extended by org.databene.benerator.sample.AbstractSampleGenerator<E>
              extended by org.databene.benerator.sample.SampleGenerator<E>
All Implemented Interfaces:
java.io.Closeable, Generator<E>, org.databene.commons.Resettable, org.databene.commons.ThreadAware
Direct Known Subclasses:
NonNullSampleGenerator

public class SampleGenerator<E>
extends AbstractSampleGenerator<E>

Generates values from a non-weighted list of samples, applying an explicitly defined distribution.

Created: 07.06.2006 19:04:08

Since:
0.1
Author:
Volker Bergmann

Field Summary
 
Fields inherited from class org.databene.benerator.util.AbstractGenerator
context, logger, state
 
Constructor Summary
SampleGenerator()
           
SampleGenerator(java.lang.Class<E> generatedType)
          Initializes the generator to an empty sample list
SampleGenerator(java.lang.Class<E> generatedType, Distribution distribution, boolean unique, java.lang.Iterable<E> values)
          Initializes the generator to a sample list
SampleGenerator(java.lang.Class<E> generatedType, Distribution distribution, E... values)
          Initializes the generator to a sample list
SampleGenerator(java.lang.Class<E> generatedType, E... values)
          Initializes the generator to a sample list
SampleGenerator(java.lang.Class<E> generatedType, java.lang.Iterable<E> values)
          Initializes the generator to a sample list
 
Method Summary
<T extends E>
void
addValue(T value)
          Adds a value to the sample list
 void clear()
          Removes all values from the sample list
 void close()
          Closes the generator.
<T extends E>
boolean
contains(E value)
           
static
<T> T
generate(java.util.List<T> samples)
          Convenience utility method that chooses one sample out of a list with uniform random distribution
 ProductWrapper<E> generate(ProductWrapper<E> wrapper)
          Returns an instance of the generic type E, using the ProductWrapper instance provided as argument.
static
<T> T
generate(T... samples)
          Convenience utility method that chooses one sample out of a list with uniform random distribution
 long getVariety()
           
 void init(GeneratorContext context)
          Initializes all attributes
 boolean isUnique()
           
 void reset()
           
 void setUnique(boolean unique)
           
 java.lang.String toString()
           
 
Methods inherited from class org.databene.benerator.sample.AbstractSampleGenerator
addValues, addValues, getGeneratedType, setValues, setValues
 
Methods inherited from class org.databene.benerator.util.ThreadSafeGenerator
isParallelizable, isThreadSafe
 
Methods inherited from class org.databene.benerator.util.AbstractGenerator
assertInitialized, assertNotInitialized, getResultWrapper, wasInitialized
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SampleGenerator

public SampleGenerator()

SampleGenerator

public SampleGenerator(java.lang.Class<E> generatedType)
Initializes the generator to an empty sample list


SampleGenerator

public SampleGenerator(java.lang.Class<E> generatedType,
                       E... values)
Initializes the generator to a sample list


SampleGenerator

public SampleGenerator(java.lang.Class<E> generatedType,
                       Distribution distribution,
                       E... values)
Initializes the generator to a sample list


SampleGenerator

public SampleGenerator(java.lang.Class<E> generatedType,
                       java.lang.Iterable<E> values)
Initializes the generator to a sample list


SampleGenerator

public SampleGenerator(java.lang.Class<E> generatedType,
                       Distribution distribution,
                       boolean unique,
                       java.lang.Iterable<E> values)
Initializes the generator to a sample list

Method Detail

addValue

public <T extends E> void addValue(T value)
Adds a value to the sample list

Specified by:
addValue in class AbstractSampleGenerator<E>

isUnique

public boolean isUnique()

setUnique

public void setUnique(boolean unique)

contains

public <T extends E> boolean contains(E value)

clear

public void clear()
Description copied from class: AbstractSampleGenerator
Removes all values from the sample list

Specified by:
clear in class AbstractSampleGenerator<E>

getVariety

public long getVariety()
Specified by:
getVariety in class AbstractSampleGenerator<E>

init

public void init(GeneratorContext context)
Initializes all attributes

Specified by:
init in interface Generator<E>
Overrides:
init in class AbstractGenerator<E>

generate

public ProductWrapper<E> generate(ProductWrapper<E> wrapper)
Description copied from interface: Generator
Returns an instance of the generic type E, using the ProductWrapper instance provided as argument. The wrapper may wrap a null value as a regular generator product. If the generator is not available (any more), it returns null instead of the ProductWrapper instance.


reset

public void reset()
Specified by:
reset in interface org.databene.commons.Resettable
Overrides:
reset in class AbstractGenerator<E>

close

public void close()
Description copied from interface: Generator
Closes the generator. After invocation the state is unavailable.

Specified by:
close in interface java.io.Closeable
Specified by:
close in interface Generator<E>
Overrides:
close in class AbstractGenerator<E>

generate

public static <T> T generate(T... samples)
Convenience utility method that chooses one sample out of a list with uniform random distribution


generate

public static <T> T generate(java.util.List<T> samples)
Convenience utility method that chooses one sample out of a list with uniform random distribution


toString

public java.lang.String toString()
Overrides:
toString in class AbstractGenerator<E>


Copyright © 2013. All Rights Reserved.