001: /*
002: * (c) Copyright 2006 by Volker Bergmann. All rights reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, is permitted under the terms of the
006: * GNU General Public License.
007: *
008: * For redistributing this software or a derivative work under a license other
009: * than the GPL-compatible Free Software License as defined by the Free
010: * Software Foundation or approved by OSI, you must first obtain a commercial
011: * license to this software product from Volker Bergmann.
012: *
013: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
014: * WITHOUT A WARRANTY OF ANY KIND. ALL EXPRESS OR IMPLIED CONDITIONS,
015: * REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF
016: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE
017: * HEREBY EXCLUDED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
018: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
019: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
020: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
021: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
022: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
023: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
024: * POSSIBILITY OF SUCH DAMAGE.
025: */
026:
027: package org.databene.benerator;
028:
029: /**
030: * Abstract Long genarator that serves as parent class for implementation of custom Sequences.<br/>
031: * <br/>
032: * Created: 07.06.2006 18:51:16
033: */
034: public abstract class AbstractLongGenerator extends
035: LightweightGenerator<Long> implements NumberGenerator<Long> {
036:
037: protected long min;
038: protected long max;
039: protected long precision;
040: protected long variation1;
041: protected long variation2;
042:
043: protected boolean dirty;
044:
045: // constructors ----------------------------------------------------------------------------------------------------
046:
047: protected AbstractLongGenerator() {
048: this (Long.MIN_VALUE, Long.MAX_VALUE);
049: }
050:
051: protected AbstractLongGenerator(long min, long max) {
052: this (min, max, 1L);
053: }
054:
055: protected AbstractLongGenerator(long min, long max, long precision) {
056: this (min, max, precision, 1L, 1L);
057: }
058:
059: protected AbstractLongGenerator(long min, long max, long precision,
060: long variation1, long variation2) {
061: setMin(min);
062: setMax(max);
063: setPrecision(precision);
064: setVariation1(variation1);
065: setVariation2(variation2);
066: this .dirty = true;
067: }
068:
069: // config properties -----------------------------------------------------------------------------------------------
070:
071: public Long getMin() {
072: return min;
073: }
074:
075: public void setMin(Long min) {
076: this .min = min;
077: this .dirty = true;
078: }
079:
080: public Long getMax() {
081: return max;
082: }
083:
084: public void setMax(Long max) {
085: this .max = max;
086: this .dirty = true;
087: }
088:
089: public Long getPrecision() {
090: return precision;
091: }
092:
093: public void setPrecision(Long precision) {
094: this .precision = precision;
095: this .dirty = true;
096: }
097:
098: public Long getVariation1() {
099: return variation1;
100: }
101:
102: public void setVariation1(Long variation1) {
103: this .variation1 = variation1;
104: this .dirty = true;
105: }
106:
107: public Long getVariation2() {
108: return variation2;
109: }
110:
111: public void setVariation2(Long variation2) {
112: this .variation2 = variation2;
113: this .dirty = true;
114: }
115:
116: // Generator interface ---------------------------------------------------------------------------------------------
117:
118: public Class<Long> getGeneratedType() {
119: return Long.class;
120: }
121:
122: public void validate() {
123: if (min > max)
124: throw new InvalidGeneratorSetupException("min", " min ("
125: + min + ") greater than max (" + max + ')');
126: super .validate();
127: this .dirty = false;
128: }
129:
130: // java.lang.Object overrides --------------------------------------------------------------------------------------
131:
132: public String toString() {
133: return getClass().getSimpleName() + "[min=" + min + ", max="
134: + max + ", precision=" + precision + ", "
135: + "variation1=" + variation1 + ", variation2="
136: + variation2 + ']';
137: }
138: }
|