1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.johnzon.core; |
20 | |
|
21 | |
import java.math.BigDecimal; |
22 | |
import java.math.BigInteger; |
23 | |
|
24 | |
import javax.json.JsonNumber; |
25 | |
|
26 | |
final class JsonNumberImpl implements JsonNumber { |
27 | |
private final BigDecimal value; |
28 | 7291 | private Integer hashCode = null; |
29 | |
|
30 | 7291 | JsonNumberImpl(final BigDecimal decimal) { |
31 | 7291 | if(decimal == null) { |
32 | 1 | throw new NullPointerException("decimal must not be null"); |
33 | |
} |
34 | |
|
35 | 7290 | this.value = decimal; |
36 | 7290 | } |
37 | |
|
38 | |
@Override |
39 | |
public boolean isIntegral() { |
40 | 1 | return value.scale() == 0; |
41 | |
} |
42 | |
|
43 | |
@Override |
44 | |
public int intValue() { |
45 | 3 | return value.intValue(); |
46 | |
} |
47 | |
|
48 | |
@Override |
49 | |
public int intValueExact() { |
50 | 0 | return value.intValueExact(); |
51 | |
} |
52 | |
|
53 | |
@Override |
54 | |
public long longValue() { |
55 | 0 | return value.longValue(); |
56 | |
} |
57 | |
|
58 | |
@Override |
59 | |
public long longValueExact() { |
60 | 0 | return value.longValueExact(); |
61 | |
} |
62 | |
|
63 | |
@Override |
64 | |
public BigInteger bigIntegerValue() { |
65 | 0 | return value.toBigInteger(); |
66 | |
} |
67 | |
|
68 | |
@Override |
69 | |
public BigInteger bigIntegerValueExact() { |
70 | 0 | return value.toBigIntegerExact(); |
71 | |
} |
72 | |
|
73 | |
@Override |
74 | |
public double doubleValue() { |
75 | 4 | return value.doubleValue(); |
76 | |
} |
77 | |
|
78 | |
@Override |
79 | |
public BigDecimal bigDecimalValue() { |
80 | 0 | return value; |
81 | |
} |
82 | |
|
83 | |
@Override |
84 | |
public ValueType getValueType() { |
85 | 3 | return ValueType.NUMBER; |
86 | |
} |
87 | |
|
88 | |
@Override |
89 | |
public String toString() { |
90 | 1 | return value.toString(); |
91 | |
} |
92 | |
|
93 | |
@Override |
94 | |
public int hashCode() { |
95 | 0 | Integer h=hashCode; |
96 | 0 | if (h == null) { |
97 | 0 | h = value.hashCode(); |
98 | 0 | hashCode=h; |
99 | |
} |
100 | 0 | return h; |
101 | |
} |
102 | |
|
103 | |
@Override |
104 | |
public boolean equals(final Object obj) { |
105 | 0 | return JsonNumber.class.isInstance(obj) && JsonNumber.class.cast(obj).bigDecimalValue().equals(value); |
106 | |
} |
107 | |
} |