Class WeightedCategoricalGenerator<T>
java.lang.Object
io.bloviate.gen.AbstractDataGenerator<T>
io.bloviate.gen.WeightedCategoricalGenerator<T>
- Type Parameters:
T- the value type
- All Implemented Interfaces:
DataGenerator<T>
Draws from a fixed set of values according to per-value weights — a categorical
distribution. For example a
status column that should be 80% ACTIVE, 15%
CHURNED, 5% BANNED instead of three equally-likely codes.
Weights need not sum to 1; each value's probability is its weight divided by the total. The
value is bound with setObject, so this works for any column type whose values you supply
as the matching Java type (strings, integers, etc.).
Reproducibility. The candidate values are arranged in a stable canonical order
(by String.valueOf(value)) before the cumulative weights are built, so the value returned
for a given draw is independent of how the weight map was constructed (e.g. an unordered
Map.of() ). Same seed ⇒ same sequence.
- Since:
- 2.11.0
-
Nested Class Summary
Nested Classes -
Field Summary
Fields inherited from class AbstractDataGenerator
random, randomUtils -
Method Summary
Methods inherited from class AbstractDataGenerator
generateAndSet, generateAsString, reseed, set
-
Method Details
-
generate
Description copied from interface:DataGeneratorGenerates a random value of type T.- Returns:
- a generated value, may be null if the generator supports nullable columns
-
get
Description copied from interface:DataGeneratorRetrieves a value from a ResultSet column.- Parameters:
resultSet- the result set to read fromcolumnIndex- the 1-based column index- Returns:
- the value from the result set, properly cast to type T
- Throws:
SQLException- if the database operation fails
-