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>
Fluent builder for
WeightedCategoricalGenerator.- Since:
- 2.11.0
-
Field Summary
Fields inherited from class AbstractBuilder
DEFAULT_REFERENCE, random -
Constructor Summary
ConstructorsConstructorDescriptionBuilder(RandomGenerator random) Creates a builder backed by the given seeded random source. -
Method Summary
Modifier and TypeMethodDescriptionAdds one value with its (positive) weight.build()Builds and returns a configured data generator.Adds every value/weight pair from the map.
-
Constructor Details
-
Builder
Creates a builder backed by the given seeded random source.- Parameters:
random- the random source used to draw generated values
-
-
Method Details
-
add
Adds one value with its (positive) weight. Calls accumulate, so this can be chained.- Parameters:
value- the value to emitweight- the relative weight of the value; must be positive- Returns:
- this builder, for chaining
-
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:BuilderBuilds and returns a configured data generator.- Returns:
- a new
DataGeneratorconfigured with the builder's settings
-