001: package org.databene.benerator;
002:
003: /**
004: * Abstract Double genarator that serves as parent class for implementation of custom Sequences.<br/>
005: * <br/>
006: * Created: 07.06.2006 18:51:16
007: */
008: public abstract class AbstractDoubleGenerator extends
009: LightweightGenerator<Double> implements NumberGenerator<Double> {
010:
011: /** The minimum value to create */
012: protected double min;
013:
014: /** The maximum value to create */
015: protected double max;
016:
017: /** the precision used */
018: protected double precision;
019:
020: /** first distribution parameter */
021: protected double variation1;
022:
023: /** second distribution parameter */
024: protected double variation2;
025:
026: /** consistency flag */
027: protected boolean dirty;
028:
029: // constructors ----------------------------------------------------------------------------------------------------
030:
031: protected AbstractDoubleGenerator() {
032: this (Double.MIN_VALUE, Double.MAX_VALUE);
033: }
034:
035: protected AbstractDoubleGenerator(double min, double max) {
036: this (min, max, 1L);
037: }
038:
039: protected AbstractDoubleGenerator(double min, double max,
040: double precision) {
041: this (min, max, precision, 1L, 1L);
042: }
043:
044: protected AbstractDoubleGenerator(double min, double max,
045: double precision, double variation1, double variation2) {
046: if (min > max)
047: throw new IllegalArgumentException("min. value (" + min
048: + ") is greater than max. value (" + max + ')');
049: this .min = min;
050: this .max = max;
051: if (precision < 0)
052: throw new IllegalArgumentException(
053: "Unsupported precision: " + precision);
054: this .precision = precision;
055: this .variation1 = variation1;
056: this .variation2 = variation2;
057: this .dirty = true;
058: }
059:
060: // config properties -----------------------------------------------------------------------------------------------
061:
062: public Double getMin() {
063: return min;
064: }
065:
066: public void setMin(Double min) {
067: this .min = min;
068: this .dirty = true;
069: }
070:
071: public Double getMax() {
072: return max;
073: }
074:
075: public void setMax(Double max) {
076: this .max = max;
077: this .dirty = true;
078: }
079:
080: public Double getPrecision() {
081: return precision;
082: }
083:
084: public void setPrecision(Double precision) {
085: this .precision = precision;
086: this .dirty = true;
087: }
088:
089: public Double getVariation1() {
090: return variation1;
091: }
092:
093: public void setVariation1(Double variation1) {
094: this .variation1 = variation1;
095: this .dirty = true;
096: }
097:
098: public Double getVariation2() {
099: return variation2;
100: }
101:
102: public void setVariation2(Double variation2) {
103: this .variation2 = variation2;
104: this .dirty = true;
105: }
106:
107: // Generator interface ---------------------------------------------------------------------------------------------
108:
109: public Class<Double> getGeneratedType() {
110: return Double.class;
111: }
112:
113: public void validate() {
114: if (dirty) {
115: if (min > max)
116: throw new InvalidGeneratorSetupException("min",
117: "greater than max (" + min + ")");
118: super .validate();
119: dirty = false;
120: }
121: }
122:
123: // java.lang.Object overrides --------------------------------------------------------------------------------------
124:
125: public String toString() {
126: return getClass().getSimpleName() + "[min=" + min + ", max="
127: + max + ", precision=" + precision + ", "
128: + "variation1=" + variation1 + ", variation2="
129: + variation2 + ']';
130: }
131: }
|