source: fedd/abac-src/rtml/src/edu/stanford/rt/datatype/todo/DecimalType.java1 @ 8780cbec

axis_examplecompt_changesinfo-opsversion-1.30version-2.00version-3.01version-3.02
Last change on this file since 8780cbec was 8780cbec, checked in by Jay Jacobs <Jay.Jacobs@…>, 15 years ago

ABAC sources from Cobham

  • Property mode set to 100644
File size: 2.2 KB
Line 
1
2package edu.stanford.rt.datatype;
3
4// Not yet implemented
5
6/**
7    IntegerType defines the integer type. The name for this type is "IntegerType".
8    It has the following attributes: min, max, base, and step.
9   
10*/
11public class DecimalType extends SimpleType
12{
13    private long min;
14    private long max;
15    private boolean minIncluded = true;
16    private boolean maxIncluded = true;
17    private long base;
18    private long step;
19
20    /**
21         
22    */
23    public DecimalType (String n, long mi, boolean mii,
24                    long ma, boolean mai, long b, long s)
25        throws IllegalArgumentException
26    {
27        super(n);
28       
29        // Check to make sure that at least one value is legal
30        if (mi > ma) {
31            throw new IllegalArgumentException("IntegerType: min > max");
32        }
33        if(b < mi || b > ma) {
34            throw new IllegalArgumentException(
35                "IntegerType: base in not within min and max");
36        }
37        if (s <= 0) {
38            throw new IllegalArgumentException("IntegerType: step <= 0");
39        }
40
41        long x = (mi - rem) % s;
42        if (x>0 && (mi + s-x)>ma) {
43            throw new IllegalArgumentException(
44                "IntegerType: First legal value is out of bound.");
45        }
46       
47        min = mi;
48        max = ma;
49        minIncluded = mii;
50        maxIncluded = mai;
51        base = b;
52        step = s;
53    }
54   
55    public long getMin()
56    {
57        return min;
58    }
59    public long getMax()
60    {
61        return max;
62    }
63    public boolean isMinIncluded()
64    {
65        return minIncluded;
66    }
67    public boolean isMaxIncluded()
68    {
69        return maxIncluded;
70    }
71    public long getBase()
72    {
73        return base;
74    }
75    public long getStep()
76    {
77        return step;
78    }
79   
80    public boolean isValidValue(DataValue v)
81    {
82        if (!(v instanceof DecimalValue)) {
83            return false;
84        }
85       
86        double l = ((DecimalValue)v).getValue();
87        if (l >= min && l<= max && ((l-remainder) % step == 0)) {
88            return true;
89        }
90        return false;
91    }
92}
Note: See TracBrowser for help on using the repository browser.