org.databene.benerator.sample
Class AttachedWeightSampleGenerator<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.AttachedWeightSampleGenerator<E>
All Implemented Interfaces:
java.io.Closeable, Generator<E>, org.databene.commons.Resettable, org.databene.commons.ThreadAware
Direct Known Subclasses:
CityGenerator, CountryGenerator

public class AttachedWeightSampleGenerator<E>
extends AbstractSampleGenerator<E>

Generates values from a weighted or non-weighted set of samples.

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, state
 
Constructor Summary
AttachedWeightSampleGenerator()
          Initializes the generator to an empty sample list
AttachedWeightSampleGenerator(java.lang.Class<E> generatedType)
          Initializes the generator to an empty sample list
AttachedWeightSampleGenerator(java.lang.Class<E> generatedType, Distribution distribution, E... values)
          Initializes the generator to an unweighted sample list
AttachedWeightSampleGenerator(java.lang.Class<E> generatedType, Distribution distribution, java.lang.Iterable<E> values)
          Initializes the generator to an unweighted sample list
AttachedWeightSampleGenerator(java.lang.Class<E> generatedType, E... values)
          Initializes the generator to an unweighted sample list
AttachedWeightSampleGenerator(java.lang.Class<E> generatedType, java.lang.Iterable<E> values)
          Initializes the generator to an unweighted sample list
 
Method Summary
<T extends E>
void
addSample(T value, double weight)
          Adds weighted values to the sample list
 void addSample(WeightedSample<? extends E> sample)
          Adds a weighted value to the sample list
<T extends E>
void
addValue(T value)
          Adds an unweighted value to the sample list
 void clear()
          Removes all values from the sample list
 E generate()
          Returns an instance of the generic type E.
static
<T> T
generate(java.util.List<T> samples)
          Convenience utility method that chooses one sample out of a list with uniform random distribution
static
<T> T
generate(T... samples)
          Convenience utility method that chooses one sample out of a list with uniform random distribution
 Distribution getDistribution()
           
 java.lang.Class<E> getGeneratedType()
          Declares the type of the objects returned by the generate() method.
 java.util.List<WeightedSample<? extends E>> getSamples()
          returns the sample list
 void init(GeneratorContext context)
          Initializes all attributes
 void setDistribution(Distribution distribution)
           
 void setSamples(java.util.Collection<WeightedSample<E>> samples)
          Adds weighted values to the sample list
 void setSamples(WeightedSample<? extends E>... samples)
          Sets the sample list to the specified weighted values
 java.lang.String toString()
           
 
Methods inherited from class org.databene.benerator.sample.AbstractSampleGenerator
addValues, addValues, setValues, setValues
 
Methods inherited from class org.databene.benerator.util.ThreadSafeGenerator
isParallelizable, isThreadSafe
 
Methods inherited from class org.databene.benerator.util.AbstractGenerator
assertInitialized, assertNotInitialized, close, reset, wasInitialized
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AttachedWeightSampleGenerator

public AttachedWeightSampleGenerator()
Initializes the generator to an empty sample list


AttachedWeightSampleGenerator

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


AttachedWeightSampleGenerator

public AttachedWeightSampleGenerator(java.lang.Class<E> generatedType,
                                     E... values)
Initializes the generator to an unweighted sample list


AttachedWeightSampleGenerator

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


AttachedWeightSampleGenerator

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


AttachedWeightSampleGenerator

public AttachedWeightSampleGenerator(java.lang.Class<E> generatedType,
                                     Distribution distribution,
                                     java.lang.Iterable<E> values)
Initializes the generator to an unweighted sample list

Method Detail

getDistribution

public Distribution getDistribution()

setDistribution

public void setDistribution(Distribution distribution)

getSamples

public java.util.List<WeightedSample<? extends E>> getSamples()
returns the sample list


setSamples

public void setSamples(WeightedSample<? extends E>... samples)
Sets the sample list to the specified weighted values


setSamples

public void setSamples(java.util.Collection<WeightedSample<E>> samples)
Adds weighted values to the sample list


addSample

public <T extends E> void addSample(T value,
                                    double weight)
Adds weighted values to the sample list


addSample

public void addSample(WeightedSample<? extends E> sample)
Adds a weighted value to the sample list


addValue

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

Specified by:
addValue in class AbstractSampleGenerator<E>

clear

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

Specified by:
clear in class AbstractSampleGenerator<E>

getGeneratedType

public java.lang.Class<E> getGeneratedType()
Description copied from interface: Generator
Declares the type of the objects returned by the generate() method.

Specified by:
getGeneratedType in interface Generator<E>
Overrides:
getGeneratedType 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 E generate()
Description copied from interface: Generator
Returns an instance of the generic type E.

See Also:
Generator.generate()

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 © 2011. All Rights Reserved.