1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package gov.nasa.pds.tools.dict.type;
17
18 /***
19 * @author pramirez
20 * @version $Revision: 2655 $
21 *
22 */
23 public class NonDecimalChecker extends LengthChecker implements NumericTypeChecker {
24
25
26
27
28 public Object cast(String value) throws InvalidTypeException {
29 Long longValue = null;
30
31 try {
32
33 if (value.indexOf("#") != -1) {
34 int radix = Integer.parseInt(value.substring(0, value.indexOf("#")));
35 String numericValue = value.substring(value.indexOf("#")+1, value.length()-1);
36 String sign = null;
37 if (numericValue.startsWith("+") || numericValue.startsWith("-")) {
38 sign = numericValue.substring(0,1);
39 numericValue = numericValue.substring(1);
40 }
41 longValue = Long.valueOf(numericValue, radix);
42 if ("-".equals(sign))
43 longValue = new Long((long)-1.0 * longValue.longValue());
44 } else
45 longValue = Long.valueOf(value);
46 } catch (NumberFormatException nfe) {
47 throw new InvalidTypeException("Could not create a non decimal value from " + value);
48 }
49 return longValue;
50 }
51
52
53
54
55 public void checkMinValue(Number value, Number min) throws OutOfRangeException {
56 if (value.longValue() < min.longValue())
57 throw new OutOfRangeException(value.toString() + " is less than the acceptable minimum of " + min.toString());
58 }
59
60
61
62
63 public void checkMaxValue(Number value, Number max) throws OutOfRangeException {
64 if (value.longValue() > max.longValue())
65 throw new OutOfRangeException(value.toString() + " exceeds acceptable maximum of " + max.toString());
66 }
67
68 }