Class SampleGenerator<E>
- java.lang.Object
-
- com.rapiddweller.benerator.util.AbstractGenerator<E>
-
- com.rapiddweller.benerator.util.ThreadSafeGenerator<E>
-
- com.rapiddweller.benerator.sample.AbstractSampleGenerator<E>
-
- com.rapiddweller.benerator.sample.SampleGenerator<E>
-
- Type Parameters:
E
- the type parameter
- All Implemented Interfaces:
Generator<E>
,com.rapiddweller.common.Resettable
,com.rapiddweller.common.ThreadAware
,java.io.Closeable
,java.lang.AutoCloseable
- 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 com.rapiddweller.benerator.util.AbstractGenerator
context, logger, state
-
-
Constructor Summary
Constructors Constructor Description SampleGenerator()
Instantiates a new Sample generator.SampleGenerator(java.lang.Class<E> generatedType)
Initializes the generator to an empty sample listSampleGenerator(java.lang.Class<E> generatedType, Distribution distribution, boolean unique, java.lang.Iterable<E> values)
Initializes the generator to a sample listSampleGenerator(java.lang.Class<E> generatedType, Distribution distribution, E... values)
Initializes the generator to a sample listSampleGenerator(java.lang.Class<E> generatedType, E... values)
Initializes the generator to a sample listSampleGenerator(java.lang.Class<E> generatedType, java.lang.Iterable<E> values)
Initializes the generator to a sample list
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T extends E>
voidaddValue(T value)
Adds a value to the sample listvoid
clear()
Removes all values from the sample listvoid
close()
Closes the generator.<T extends E>
booleancontains(E value)
Contains boolean.ProductWrapper<E>
generate(ProductWrapper<E> wrapper)
Returns an instance of the generic type E, using theProductWrapper
instance provided as argument.static <T> T
generate(java.util.List<T> samples)
Convenience utility method that chooses one sample out of a list with uniform random distributionstatic <T> T
generate(T... samples)
Convenience utility method that chooses one sample out of a list with uniform random distributionlong
getVariety()
Gets variety.void
init(GeneratorContext context)
Initializes all attributesboolean
isUnique()
Is unique boolean.void
reset()
void
setUnique(boolean unique)
Sets unique.java.lang.String
toString()
-
Methods inherited from class com.rapiddweller.benerator.sample.AbstractSampleGenerator
addValues, addValues, getGeneratedType, setValues, setValues
-
Methods inherited from class com.rapiddweller.benerator.util.ThreadSafeGenerator
isParallelizable, isThreadSafe
-
Methods inherited from class com.rapiddweller.benerator.util.AbstractGenerator
assertInitialized, assertNotInitialized, getResultWrapper, wasInitialized
-
-
-
-
Constructor Detail
-
SampleGenerator
public SampleGenerator()
Instantiates a new Sample generator.
-
SampleGenerator
public SampleGenerator(java.lang.Class<E> generatedType)
Initializes the generator to an empty sample list- Parameters:
generatedType
- the generated type
-
SampleGenerator
@SafeVarargs public SampleGenerator(java.lang.Class<E> generatedType, E... values)
Initializes the generator to a sample list- Parameters:
generatedType
- the generated typevalues
- the values
-
SampleGenerator
@SafeVarargs public SampleGenerator(java.lang.Class<E> generatedType, Distribution distribution, E... values)
Initializes the generator to a sample list- Parameters:
generatedType
- the generated typedistribution
- the distributionvalues
- the values
-
SampleGenerator
public SampleGenerator(java.lang.Class<E> generatedType, java.lang.Iterable<E> values)
Initializes the generator to a sample list- Parameters:
generatedType
- the generated typevalues
- the values
-
SampleGenerator
public SampleGenerator(java.lang.Class<E> generatedType, Distribution distribution, boolean unique, java.lang.Iterable<E> values)
Initializes the generator to a sample list- Parameters:
generatedType
- the generated typedistribution
- the distributionunique
- the uniquevalues
- the values
-
-
Method Detail
-
generate
@SafeVarargs public static <T> T generate(T... samples)
Convenience utility method that chooses one sample out of a list with uniform random distribution- Type Parameters:
T
- the type parameter- Parameters:
samples
- the samples- Returns:
- the t
-
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- Type Parameters:
T
- the type parameter- Parameters:
samples
- the samples- Returns:
- the t
-
isUnique
public boolean isUnique()
Is unique boolean.- Returns:
- the boolean
-
setUnique
public void setUnique(boolean unique)
Sets unique.- Parameters:
unique
- the unique
-
contains
public <T extends E> boolean contains(E value)
Contains boolean.- Type Parameters:
T
- the type parameter- Parameters:
value
- the value- Returns:
- the boolean
-
clear
public void clear()
Description copied from class:AbstractSampleGenerator
Removes all values from the sample list- Specified by:
clear
in classAbstractSampleGenerator<E>
-
getVariety
public long getVariety()
Description copied from class:AbstractSampleGenerator
Gets variety.- Specified by:
getVariety
in classAbstractSampleGenerator<E>
- Returns:
- the variety
-
init
public void init(GeneratorContext context)
Initializes all attributes
-
addValue
public <T extends E> void addValue(T value)
Adds a value to the sample list- Specified by:
addValue
in classAbstractSampleGenerator<E>
- Type Parameters:
T
- the type parameter- Parameters:
value
- the value
-
generate
public ProductWrapper<E> generate(ProductWrapper<E> wrapper)
Description copied from interface:Generator
Returns an instance of the generic type E, using theProductWrapper
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.- Parameters:
wrapper
- the wrapper- Returns:
- the product wrapper
-
reset
public void reset()
- Specified by:
reset
in interfacecom.rapiddweller.common.Resettable
- Overrides:
reset
in classAbstractGenerator<E>
-
close
public void close()
Description copied from interface:Generator
Closes the generator. After invocation the state is unavailable.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classAbstractGenerator<E>
-
-