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>

public class WeightedCategoricalGenerator<T> extends AbstractDataGenerator<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
  • Method Details

    • generate

      public T generate()
      Description copied from interface: DataGenerator
      Generates a random value of type T.
      Returns:
      a generated value, may be null if the generator supports nullable columns
    • get

      public T get(ResultSet resultSet, int columnIndex) throws SQLException
      Description copied from interface: DataGenerator
      Retrieves a value from a ResultSet column.
      Parameters:
      resultSet - the result set to read from
      columnIndex - the 1-based column index
      Returns:
      the value from the result set, properly cast to type T
      Throws:
      SQLException - if the database operation fails