KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > datatypes > IntegerDataType


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

10 package org.mmbase.datatypes;
11 import org.mmbase.util.Casting;
12
13 /**
14  * DataType associated with {@link java.lang.Integer}, a NumberDataType, but provides getMin and getMax as int.
15  *
16  * @author Pierre van Rooden
17  * @version $Id: IntegerDataType.java,v 1.10 2006/04/29 19:41:09 michiel Exp $
18  * @since MMBase-1.8
19  */

20 public class IntegerDataType extends NumberDataType {
21     private static final long serialVersionUID = 1L; // increase this if object serialization changes (which we shouldn't do!)
22

23     /**
24      * @param primitive indicate if a primitive type should be used
25      */

26     public IntegerDataType(String JavaDoc name, boolean primitive) {
27         super(name, primitive ? Integer.TYPE : Integer JavaDoc.class);
28         setMin(new Integer JavaDoc(Integer.MIN_VALUE), true);
29         minRestriction.setEnforceStrength(ENFORCE_ABSOLUTE);
30         setMax(new Integer JavaDoc(Integer.MAX_VALUE), true);
31         maxRestriction.setEnforceStrength(ENFORCE_ABSOLUTE);
32     }
33
34     protected void inheritRestrictions(BasicDataType origin) {
35         super.inheritRestrictions(origin);
36         if (origin instanceof BooleanDataType) {
37             setMin(new Integer JavaDoc(0), true);
38             setMax(new Integer JavaDoc(1), true);
39         }
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         Object JavaDoc 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         Object JavaDoc max = getMaxRestriction().getValue();
56         return max == null ? Integer.MAX_VALUE : Casting.toInt(max);
57     }
58
59 }
60
Popular Tags