dev.marksman.composablerandom.frequency.FrequencyMapBuilder Maven / Gradle / Ivy
package dev.marksman.composablerandom.frequency;
import com.jnape.palatable.lambda.functions.Fn1;
import dev.marksman.composablerandom.FrequencyEntry;
import dev.marksman.composablerandom.Generator;
import static dev.marksman.composablerandom.Generator.constant;
import static dev.marksman.composablerandom.frequency.FrequencyMapBuilder0.frequencyMapBuilder0;
public interface FrequencyMapBuilder {
FrequencyMapBuilder add(int weight, Generator extends A> generator);
FrequencyMapBuilder combine(FrequencyMap other);
FrequencyMap build();
FrequencyMapBuilder fmap(Fn1 super A, ? extends B> fn);
FrequencyMapBuilder multiply(int positiveFactor);
default FrequencyMapBuilder add(Generator extends A> generator) {
return add(1, generator);
}
default FrequencyMapBuilder addValue(int weight, A value) {
return add(weight, constant(value));
}
default FrequencyMapBuilder addValue(A value) {
return add(1, constant(value));
}
default FrequencyMapBuilder add(FrequencyEntry entry) {
return add(entry.getWeight(), entry.getGenerator());
}
static FrequencyMapBuilder frequencyMapBuilder() {
return frequencyMapBuilder0();
}
}