org.databene.benerator.distribution.sequence
Class ExpandGeneratorProxy<E>

java.lang.Object
  extended by org.databene.benerator.util.AbstractGenerator<P>
      extended by org.databene.benerator.wrapper.GeneratorWrapper<E,E>
          extended by org.databene.benerator.wrapper.GeneratorProxy<E>
              extended by org.databene.benerator.distribution.sequence.ExpandGeneratorProxy<E>
All Implemented Interfaces:
java.io.Closeable, Generator<E>, org.databene.commons.Resettable, org.databene.commons.ThreadAware

public class ExpandGeneratorProxy<E>
extends GeneratorProxy<E>

GeneratorProxy implementation that supports distribution of unlimited data volumes (provided by a source generator) in a unique or non-unique manner. Handling of unlimited data volume is provided with a cache of limited size, distribution is implemented by distributing source data randomly over buckets and uniqueness can be assured (when setting duplicationQuota to 0) by removing used data from its bucket.
For maximum efficiency, source data first is randomly distributed over buckets of limited size. As long as further source data is available, the proxy randomly selects an entry from a random bucket returns it to the caller and replaces it with new data if no duplicates are allowed or should not be applied in this case. If no more source data is available, the proxy returns the last element from a bucket, allowing to reduce the used bucket size without shifting elements. If a bucket is empty, it is removed.
The buckets were introduced for quickly freeing RAM after usage and for allowing a more erratic behavior in the phase when no more source data is available and elements are taken from bucket end to beginning.

Created: 10.12.2009 11:32:35

Since:
0.6.0
Author:
Volker Bergmann

Field Summary
static float DEFAULT_DUPLICATION_QUOTA
           
static int MIN_BUCKET_SIZE
           
 
Fields inherited from class org.databene.benerator.wrapper.GeneratorProxy
generatedType
 
Fields inherited from class org.databene.benerator.util.AbstractGenerator
context, logger, state
 
Constructor Summary
ExpandGeneratorProxy(Generator<E> source, float duplicationQuota)
           
ExpandGeneratorProxy(Generator<E> source, float duplicationQuota, int cacheSize)
           
ExpandGeneratorProxy(Generator<E> source, float duplicationQuota, int cacheSize, int bucketSize)
           
 
Method Summary
static int defaultBucketSize(int cacheSize)
           
 ProductWrapper<E> generate(ProductWrapper<E> wrapper)
          Returns an instance of the generic type E, using the ProductWrapper instance provided as argument.
 int getBucketSize()
           
 int getCacheSize()
           
 float getDuplicationQuota()
           
 void init(GeneratorContext context)
           
 void printState()
           
 void reset()
           
 void setBucketSize(int bucketSize)
           
 void setCacheSize(int cacheSize)
           
 void setDuplicationQuota(float duplicationQuota)
           
static
<T> ExpandGeneratorProxy<T>
uniqueProxy(Generator<T> source, int cacheSize, int bucketSize)
           
 
Methods inherited from class org.databene.benerator.wrapper.GeneratorProxy
getGeneratedType, toString
 
Methods inherited from class org.databene.benerator.wrapper.GeneratorWrapper
close, equals, generateFromSource, getSource, getSourceWrapper, hashCode, isParallelizable, isThreadSafe, setSource
 
Methods inherited from class org.databene.benerator.util.AbstractGenerator
assertInitialized, assertNotInitialized, getResultWrapper, wasInitialized
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

MIN_BUCKET_SIZE

public static final int MIN_BUCKET_SIZE
See Also:
Constant Field Values

DEFAULT_DUPLICATION_QUOTA

public static final float DEFAULT_DUPLICATION_QUOTA
See Also:
Constant Field Values
Constructor Detail

ExpandGeneratorProxy

public ExpandGeneratorProxy(Generator<E> source,
                            float duplicationQuota)

ExpandGeneratorProxy

public ExpandGeneratorProxy(Generator<E> source,
                            float duplicationQuota,
                            int cacheSize)

ExpandGeneratorProxy

public ExpandGeneratorProxy(Generator<E> source,
                            float duplicationQuota,
                            int cacheSize,
                            int bucketSize)
Method Detail

uniqueProxy

public static <T> ExpandGeneratorProxy<T> uniqueProxy(Generator<T> source,
                                                      int cacheSize,
                                                      int bucketSize)

defaultBucketSize

public static int defaultBucketSize(int cacheSize)

getCacheSize

public int getCacheSize()

setCacheSize

public void setCacheSize(int cacheSize)

getDuplicationQuota

public float getDuplicationQuota()

setDuplicationQuota

public void setDuplicationQuota(float duplicationQuota)

getBucketSize

public int getBucketSize()

setBucketSize

public void setBucketSize(int bucketSize)

init

public void init(GeneratorContext context)
Specified by:
init in interface Generator<E>
Overrides:
init in class GeneratorWrapper<E,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.

Specified by:
generate in interface Generator<E>
Overrides:
generate in class GeneratorProxy<E>

reset

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

printState

public void printState()


Copyright © 2013. All Rights Reserved.