com.robertboothby.djenni.distribution.simple.SimpleRandomLongDistribution Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of core Show documentation
Show all versions of core Show documentation
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.
package com.robertboothby.djenni.distribution.simple;
import com.robertboothby.djenni.distribution.Distribution;
import org.hamcrest.Description;
/**
*
* @author robertboothby
*/
public class SimpleRandomLongDistribution implements Distribution {
private final SimpleRandomDoubleDistribution underlyingDistribution;
/**
* This distribution generates Longs following the distribution defined in {@link SimpleRandomLongDistribution#UNIFORM}.
*/
public static final SimpleRandomLongDistribution UNIFORM =
new SimpleRandomLongDistribution(SimpleRandomDoubleDistribution.UNIFORM);
/**
* This distribution generates Longs following the distribution defined in {@link SimpleRandomLongDistribution#NORMAL}.
*/
public static final SimpleRandomLongDistribution NORMAL =
new SimpleRandomLongDistribution(SimpleRandomDoubleDistribution.NORMAL);
/**
* This distribution generates Longs following the distribution defined in {@link SimpleRandomLongDistribution#LEFT_NORMAL}.
*/
public static final SimpleRandomLongDistribution LEFT_NORMAL =
new SimpleRandomLongDistribution(SimpleRandomDoubleDistribution.LEFT_NORMAL);
/**
* This distribution generates Longs following the distribution defined in {@link SimpleRandomLongDistribution#RIGHT_NORMAL}.
*/
public static final SimpleRandomLongDistribution RIGHT_NORMAL =
new SimpleRandomLongDistribution(SimpleRandomDoubleDistribution.RIGHT_NORMAL);
/**
* This distribution generates Longs following the distribution defined in {@link SimpleRandomLongDistribution#INVERTED_NORMAL}.
*/
public static final SimpleRandomLongDistribution INVERTED_NORMAL =
new SimpleRandomLongDistribution(SimpleRandomDoubleDistribution.INVERTED_NORMAL);
/**
* This distribution generates Longs following the distribution defined in {@link SimpleRandomLongDistribution#LEFT_INVERTED_NORMAL}.
*/
public static final SimpleRandomLongDistribution LEFT_INVERTED_NORMAL =
new SimpleRandomLongDistribution(SimpleRandomDoubleDistribution.LEFT_INVERTED_NORMAL);
/**
* This distribution generates Longs following the distribution defined in {@link SimpleRandomLongDistribution#RIGHT_INVERTED_NORMAL}.
*/
public static final SimpleRandomLongDistribution RIGHT_INVERTED_NORMAL =
new SimpleRandomLongDistribution(SimpleRandomDoubleDistribution.RIGHT_INVERTED_NORMAL);
/**
* Construct an instance of the distribution using the underlying distribution.
* @param underlyingDistribution The underlying distribution to use.
*/
public SimpleRandomLongDistribution(SimpleRandomDoubleDistribution underlyingDistribution) {
this.underlyingDistribution = underlyingDistribution;
}
@Override
public Long generate(Long bound) {
return (long) Math.floor(underlyingDistribution.nextDouble() * bound);
}
}