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

com.robertboothby.djenni.distribution.simple.SimpleRandomBigIntegerDistribution 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.distribution.simple;

import com.robertboothby.djenni.distribution.Distribution;
import org.hamcrest.Description;

import java.math.BigDecimal;
import java.math.BigInteger;

/**
 * This distribution generates positive BigIntegers within the range of value that can be described by a Double.
 * @author robertboothby
 */
public abstract class SimpleRandomBigIntegerDistribution implements Distribution {

    @Override
    public abstract BigInteger generate(Double bound);

    public static final SimpleRandomBigIntegerDistribution UNIFORM = new SimpleRandomDoubleDistributionWrapper(SimpleRandomDoubleDistribution.UNIFORM);
    public static final SimpleRandomBigIntegerDistribution NORMAL = new SimpleRandomDoubleDistributionWrapper(SimpleRandomDoubleDistribution.NORMAL);
    public static final SimpleRandomBigIntegerDistribution LEFT_NORMAL = new SimpleRandomDoubleDistributionWrapper(SimpleRandomDoubleDistribution.LEFT_NORMAL);
    public static final SimpleRandomBigIntegerDistribution RIGHT_NORMAL = new SimpleRandomDoubleDistributionWrapper(SimpleRandomDoubleDistribution.RIGHT_NORMAL);
    public static final SimpleRandomBigIntegerDistribution INVERTED_NORMAL = new SimpleRandomDoubleDistributionWrapper(SimpleRandomDoubleDistribution.INVERTED_NORMAL);
    public static final SimpleRandomBigIntegerDistribution LEFT_INVERTED_NORMAL = new SimpleRandomDoubleDistributionWrapper(SimpleRandomDoubleDistribution.LEFT_INVERTED_NORMAL);
    public static final SimpleRandomBigIntegerDistribution RIGHT_INVERTED_NORMAL = new SimpleRandomDoubleDistributionWrapper(SimpleRandomDoubleDistribution.RIGHT_INVERTED_NORMAL);

    private static class SimpleRandomDoubleDistributionWrapper extends SimpleRandomBigIntegerDistribution {
        private final Distribution distribution;

        private SimpleRandomDoubleDistributionWrapper(Distribution distribution){

            this.distribution = distribution;
        }
        @Override
        public BigInteger generate(Double bound) {
            return BigDecimal.valueOf(distribution.generate(bound)).toBigInteger();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy