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

com.robertboothby.djenni.lang.BooleanSupplierBuilder Maven / Gradle / Ivy

Go to download

This module holds the core components of the Djenni data generator framework. By itself it provides most of the components to create an efficient end to end data generation framework for a specific domain. It contains the core SupplierBuilder interfaces, implementations for the core Java data types and useful test components. It is intended to be used in conjunction with the source-generator module that will speed up delivery of domain specific data generation and also with common domain modules (TBD) that deliver standard generators for common frameworks such as JAXB.

There is a newer version: 0.2.0
Show newest version
package com.robertboothby.djenni.lang;

import com.robertboothby.djenni.SupplierBuilder;
import com.robertboothby.djenni.core.ExplicitlyBiassedSupplier;
import com.robertboothby.djenni.core.StreamableSupplier;
import com.robertboothby.djenni.distribution.Distribution;
import com.robertboothby.djenni.distribution.simple.SimpleRandomDoubleDistribution;

/**
 * Trivial implementation of the {@link SupplierBuilder} inteface that is created to retain consistency with the other
 * primitive types. When explicit control is required then it is better to consider using the
 * {@link ExplicitlyBiassedSupplier}.
 *
 * @author robertboothby
 */
public class BooleanSupplierBuilder implements SupplierBuilder {

    private static final Distribution DISTRIBUTION_DEFAULT = SimpleRandomDoubleDistribution.UNIFORM;
    private Distribution distribution = DISTRIBUTION_DEFAULT;

    public static BooleanSupplierBuilder booleanSupplier() {
        return new BooleanSupplierBuilder();
    }

    public StreamableSupplier build() {
        return () -> distribution.generate(1.0D) < 0.5D;

    }

    /**
     * Configure the distribution to be used with the Suppliers that this will build.
     * @param distribution the distribution to use in any Suppliers built.
     * @return the Supplier builder for further configuration.
     */
    public BooleanSupplierBuilder withDistribution(Distribution distribution) {
        this.distribution = distribution;
        return this;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy