01: /*
02:
03: This software is OSI Certified Open Source Software.
04: OSI Certified is a certification mark of the Open Source Initiative.
05:
06: The license (Mozilla version 1.0) can be read at the MMBase site.
07: See http://www.MMBase.org/license
08:
09: */
10: package org.mmbase.datatypes;
11:
12: import org.mmbase.util.Casting;
13:
14: /**
15: * DataType associated with {@link java.lang.Integer}, a NumberDataType, but provides getMin and getMax as int.
16: *
17: * @author Pierre van Rooden
18: * @version $Id: IntegerDataType.java,v 1.11 2006/12/15 13:38:01 michiel Exp $
19: * @since MMBase-1.8
20: */
21: public class IntegerDataType extends NumberDataType<Integer> {
22: private static final long serialVersionUID = 1L; // increase this if object serialization changes (which we shouldn't do!)
23:
24: /**
25: * @param primitive indicate if a primitive type should be used
26: */
27: public IntegerDataType(String name, boolean primitive) {
28: super (name, primitive ? Integer.TYPE : Integer.class);
29: setMin(Integer.valueOf(Integer.MIN_VALUE), true);
30: minRestriction.setEnforceStrength(ENFORCE_ABSOLUTE);
31: setMax(Integer.valueOf(Integer.MAX_VALUE), true);
32: maxRestriction.setEnforceStrength(ENFORCE_ABSOLUTE);
33: }
34:
35: protected void inheritRestrictions(BasicDataType origin) {
36: super .inheritRestrictions(origin);
37: if (origin instanceof BooleanDataType) {
38: setMin(Integer.valueOf(0), true);
39: setMax(Integer.valueOf(1), true);
40: }
41: }
42:
43: /**
44: * @return the minimum value as an <code>int</code>, or a very very small number if there is no minimum.
45: */
46: public int getMin() {
47: Integer min = getMinRestriction().getValue();
48: return min == null ? Integer.MIN_VALUE : Casting.toInt(min);
49: }
50:
51: /**
52: * @return the maximum value as an <code>int</code>, or a very very big number if there is no maximum.
53: */
54: public int getMax() {
55: Integer max = getMaxRestriction().getValue();
56: return max == null ? Integer.MAX_VALUE : Casting.toInt(max);
57: }
58:
59: }
|