org.databene.benerator.wrapper
Class WeightedGeneratorGenerator<E>

java.lang.Object
  extended by org.databene.benerator.util.AbstractGenerator<P>
      extended by org.databene.benerator.wrapper.MultiGeneratorWrapper<E,Generator<E>>
          extended by org.databene.benerator.wrapper.WeightedGeneratorGenerator<E>
All Implemented Interfaces:
java.io.Closeable, Generator<Generator<E>>, org.databene.commons.Resettable, org.databene.commons.ThreadAware, org.databene.commons.Weighted

public class WeightedGeneratorGenerator<E>
extends MultiGeneratorWrapper<E,Generator<E>>
implements org.databene.commons.Weighted

Generator that wraps several other 'source generators' and assigns a weight to each one. Calls to Generator.generate(ProductWrapper) are forwarded to a random source generator, with a probability proportional to its assigned weight. If a source generator becomes unavailable, its weight is ignored.

Created: 09.03.2011 07:59:04

Since:
0.6.6
Author:
Volker Bergmann

Field Summary
 
Fields inherited from class org.databene.benerator.wrapper.MultiGeneratorWrapper
generatedType, sources
 
Fields inherited from class org.databene.benerator.util.AbstractGenerator
context, logger, state
 
Constructor Summary
WeightedGeneratorGenerator()
           
 
Method Summary
 void addSource(Generator<? extends E> source)
           
 void addSource(Generator<? extends E> source, java.lang.Double weight)
           
 void close()
          Closes the generator.
 ProductWrapper<Generator<E>> generate(ProductWrapper<Generator<E>> wrapper)
          Returns an instance of the generic type E, using the ProductWrapper instance provided as argument.
 java.util.List<java.lang.Double> getSourceWeights()
           
 double getWeight()
           
 void init(GeneratorContext context)
           
 void reset()
           
 
Methods inherited from class org.databene.benerator.wrapper.MultiGeneratorWrapper
availableSourceCount, generateFromAllSources, generateFromAvailableSource, generateFromRandomSource, generateFromSource, getAvailableSource, getGeneratedType, getSource, getSources, getSourceWrapper, isParallelizable, isThreadSafe, setSources, toString
 
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

WeightedGeneratorGenerator

public WeightedGeneratorGenerator()
Method Detail

getWeight

public double getWeight()
Specified by:
getWeight in interface org.databene.commons.Weighted

getSourceWeights

public java.util.List<java.lang.Double> getSourceWeights()

addSource

public void addSource(Generator<? extends E> source)
Overrides:
addSource in class MultiGeneratorWrapper<E,Generator<E>>

addSource

public void addSource(Generator<? extends E> source,
                      java.lang.Double weight)

init

public void init(GeneratorContext context)
Specified by:
init in interface Generator<Generator<E>>
Overrides:
init in class MultiGeneratorWrapper<E,Generator<E>>

generate

public ProductWrapper<Generator<E>> generate(ProductWrapper<Generator<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.

Specified by:
generate in interface Generator<Generator<E>>

reset

public void reset()
Specified by:
reset in interface org.databene.commons.Resettable
Overrides:
reset in class MultiGeneratorWrapper<E,Generator<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<Generator<E>>
Overrides:
close in class MultiGeneratorWrapper<E,Generator<E>>


Copyright © 2013. All Rights Reserved.