1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.universAAL.middleware.xsd;
21
22 import org.universAAL.middleware.rdf.TypeMapper;
23
24
25
26
27
28
29
30
31 public final class NonNegativeInteger {
32 public static final String MY_URI = TypeMapper.XSD_NAMESPACE
33 + "nonNegativeInteger";
34
35 private boolean isInt;
36
37 private int intval;
38
39
40
41 public NonNegativeInteger(int val) {
42 if (val < 0)
43 throw new IllegalArgumentException(
44 "NonNegativeInteger must be non-negative: " + val);
45 isInt = true;
46 intval = val;
47 }
48
49 public NonNegativeInteger(String val) {
50 int intval = Integer.valueOf(val).intValue();
51 if (intval < 0)
52 throw new IllegalArgumentException(
53 "NonNegativeInteger must be non-negative: " + val);
54
55 isInt = true;
56 this.intval = intval;
57
58 }
59
60 public int intValue() {
61 if (isInt)
62 return intval;
63 else
64 return Integer.MAX_VALUE;
65 }
66
67 public String toString() {
68 return Integer.toString(intval);
69 }
70
71 public boolean equals(Object obj) {
72 if (this == obj)
73 return true;
74 if (obj instanceof NonNegativeInteger)
75 return this.intval == ((NonNegativeInteger) obj).intval;
76 if (obj instanceof Integer)
77 return this.intval == ((Integer) obj).intValue();
78 return false;
79 }
80 }