All Downloads are FREE. Search and download functionalities are using the official Maven repository.

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 generator);

    FrequencyMapBuilder combine(FrequencyMap other);

    FrequencyMap build();

     FrequencyMapBuilder fmap(Fn1 fn);

    FrequencyMapBuilder multiply(int positiveFactor);

    default FrequencyMapBuilder add(Generator 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();
    }
}