dev.marksman.composablerandom.FrequencyEntry Maven / Gradle / Ivy
package dev.marksman.composablerandom;
import com.jnape.palatable.lambda.adt.product.Product2;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Value;
import static dev.marksman.composablerandom.Generator.constant;
@Value
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class FrequencyEntry implements Product2> {
private final int weight;
private final Generator generator;
@Override
public Integer _1() {
return weight;
}
@Override
public Generator _2() {
return generator;
}
public static FrequencyEntry entry(int weight, Generator generator) {
return new FrequencyEntry<>(weight, generator);
}
public static FrequencyEntry entry(Generator generator) {
return entry(1, generator);
}
public static FrequencyEntry entryForValue(int weight, A value) {
return new FrequencyEntry<>(weight, constant(value));
}
public static FrequencyEntry entryForValue(A value) {
return new FrequencyEntry<>(1, constant(value));
}
public static FrequencyEntry fromProduct(Product2> entry) {
//noinspection unchecked
return new FrequencyEntry(entry._1(), entry._2());
}
}