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 JsonDoubleImpl implements JsonNumber { |
27 | |
private final double value; |
28 | |
|
29 | 6 | JsonDoubleImpl(final double value) { |
30 | |
|
31 | 6 | if(Double.isInfinite(value) || Double.isNaN(value)) { |
32 | 3 | throw new NumberFormatException("double value must not be NaN or Infinite"); |
33 | |
} |
34 | |
|
35 | 3 | this.value = value; |
36 | 3 | } |
37 | |
|
38 | |
@Override |
39 | |
public boolean isIntegral() { |
40 | 0 | return false; |
41 | |
} |
42 | |
|
43 | |
@Override |
44 | |
public int intValue() { |
45 | 0 | return (int) value; |
46 | |
} |
47 | |
|
48 | |
@Override |
49 | |
public int intValueExact() { |
50 | 0 | return intValue(); |
51 | |
} |
52 | |
|
53 | |
@Override |
54 | |
public long longValue() { |
55 | 0 | return (long) value; |
56 | |
} |
57 | |
|
58 | |
@Override |
59 | |
public long longValueExact() { |
60 | 0 | return (long) value; |
61 | |
} |
62 | |
|
63 | |
@Override |
64 | |
public BigInteger bigIntegerValue() { |
65 | 1 | return new BigDecimal(toString()).toBigInteger(); |
66 | |
} |
67 | |
|
68 | |
@Override |
69 | |
public BigInteger bigIntegerValueExact() { |
70 | 1 | return new BigDecimal(toString()).toBigIntegerExact(); |
71 | |
} |
72 | |
|
73 | |
@Override |
74 | |
public double doubleValue() { |
75 | 0 | return value; |
76 | |
} |
77 | |
|
78 | |
@Override |
79 | |
public BigDecimal bigDecimalValue() { |
80 | 0 | return new BigDecimal(toString()); |
81 | |
} |
82 | |
|
83 | |
@Override |
84 | |
public ValueType getValueType() { |
85 | 0 | return ValueType.NUMBER; |
86 | |
} |
87 | |
|
88 | |
@Override |
89 | |
public String toString() { |
90 | 3 | return Double.toString(value); |
91 | |
} |
92 | |
|
93 | |
@Override |
94 | |
public int hashCode() { |
95 | 0 | return Double.valueOf(value).hashCode(); |
96 | |
} |
97 | |
|
98 | |
@Override |
99 | |
public boolean equals(final Object obj) { |
100 | 0 | return JsonNumber.class.isInstance(obj) && JsonNumber.class.cast(obj).doubleValue() == value; |
101 | |
} |
102 | |
} |