Class WeightedCategoricalGenerator.Builder<T>

java.lang.Object
io.bloviate.gen.AbstractBuilder<T>
io.bloviate.gen.WeightedCategoricalGenerator.Builder<T>
Type Parameters:
T - the category value type produced by the generator
All Implemented Interfaces:
Builder<T>
Enclosing class:
WeightedCategoricalGenerator<T>

public static class WeightedCategoricalGenerator.Builder<T> extends AbstractBuilder<T>
Fluent builder for WeightedCategoricalGenerator.
Since:
2.11.0
  • Constructor Details

    • Builder

      public Builder(RandomGenerator random)
      Creates a builder backed by the given seeded random source.
      Parameters:
      random - the random source used to draw generated values
  • Method Details

    • add

      public WeightedCategoricalGenerator.Builder<T> add(T value, double weight)
      Adds one value with its (positive) weight. Calls accumulate, so this can be chained.
      Parameters:
      value - the value to emit
      weight - the relative weight of the value; must be positive
      Returns:
      this builder, for chaining
    • weights

      public WeightedCategoricalGenerator.Builder<T> weights(Map<? extends T, ? extends Number> weights)
      Adds every value/weight pair from the map. Order is irrelevant — the generator imposes a stable canonical order so output is reproducible regardless of the map's iteration order.
      Parameters:
      weights - a map of values to their relative (positive) weights
      Returns:
      this builder, for chaining
    • build

      Description copied from interface: Builder
      Builds and returns a configured data generator.
      Returns:
      a new DataGenerator configured with the builder's settings