1
|
|
/*
|
2
|
|
* JBind
|
3
|
|
*
|
4
|
|
* Copyright (c) by Stefan Wachter. All rights reserved.
|
5
|
|
*
|
6
|
|
* Usage, modification, and redistribution is subject to license terms that are
|
7
|
|
* available at 'http://www.jbind.org'. The JBind license is like the
|
8
|
|
* 'Apache Software License V 1.1'.
|
9
|
|
*/
|
10
|
|
package org.jbind.xml.instance.data;
|
11
|
|
|
12
|
|
import org.jbind.xml.core.data.IAnyTypeData;
|
13
|
|
import org.jbind.xml.core.data.IDoubleData;
|
14
|
|
import org.jbind.xml.core.data.IHasOrder;
|
15
|
|
import org.jbind.xml.msg.IConstraintViolations;
|
16
|
|
import org.jbind.xml.msg.XmlException;
|
17
|
|
import org.jbind.xml.msg.XmlMessages;
|
18
|
|
|
19
|
|
public class DoubleData extends AbstractSimpleData implements IDoubleData {
|
20
|
|
|
21
|
|
private double myValue;
|
22
|
|
|
23
|
31
|
protected void doAccept(String aString) throws XmlException {
|
24
|
31
|
super.doAccept(aString);
|
25
|
31
|
try {
|
26
|
31
|
if ("INF".equals(aString)) {
|
27
|
0
|
myValue = Double.POSITIVE_INFINITY;
|
28
|
31
|
} else if ("-INF".equals(aString)) {
|
29
|
0
|
myValue = Double.NEGATIVE_INFINITY;
|
30
|
|
} else {
|
31
|
31
|
myValue = Double.parseDouble(aString);
|
32
|
|
}
|
33
|
|
} catch (NumberFormatException e) {
|
34
|
0
|
throw new XmlException(XmlMessages.simpleDataConversionException(aString, e, getImpl_()));
|
35
|
|
}
|
36
|
|
}
|
37
|
|
|
38
|
0
|
public String getCanonicalForm_() {
|
39
|
0
|
if (myValue == Double.NEGATIVE_INFINITY) {
|
40
|
0
|
return "-INF";
|
41
|
|
}
|
42
|
0
|
if (myValue == Double.POSITIVE_INFINITY) {
|
43
|
0
|
return "INF";
|
44
|
|
}
|
45
|
0
|
return String.valueOf(myValue);
|
46
|
|
}
|
47
|
|
|
48
|
5
|
public double getDouble() {
|
49
|
5
|
return myValue;
|
50
|
|
}
|
51
|
|
|
52
|
0
|
public void setDouble(double aNewValue) throws XmlException {
|
53
|
0
|
double oldValue = myValue;
|
54
|
0
|
myValue = aNewValue;
|
55
|
0
|
IConstraintViolations violations = completeSimpleStorageAssignment_();
|
56
|
0
|
if (!violations.isEmpty()) {
|
57
|
0
|
myValue = oldValue;
|
58
|
0
|
throw new XmlException(violations);
|
59
|
|
}
|
60
|
|
}
|
61
|
|
|
62
|
4
|
public boolean simpleStorageValueEquals(IAnyTypeData aData) {
|
63
|
4
|
return (aData instanceof IDoubleData) && (Double.doubleToLongBits(((IDoubleData)aData).getDouble()) == Double.doubleToLongBits(myValue));
|
64
|
|
}
|
65
|
|
|
66
|
15
|
public int simpleStorageValueHashCode() {
|
67
|
15
|
long bits = Double.doubleToLongBits(myValue);
|
68
|
15
|
return (int)(bits ^ (bits >>> 32));
|
69
|
|
}
|
70
|
|
|
71
|
1
|
public Object getSimpleStorageObject() {
|
72
|
1
|
return new Double(myValue);
|
73
|
|
}
|
74
|
|
|
75
|
0
|
public void setSimpleStorageObject(Object aValue) {
|
76
|
0
|
myValue = ((Double)aValue).doubleValue();
|
77
|
|
}
|
78
|
|
|
79
|
0
|
public boolean isEqual(IHasOrder aData) {
|
80
|
0
|
double d = ((IDoubleData)aData).getDouble();
|
81
|
0
|
return myValue == d;
|
82
|
|
}
|
83
|
|
|
84
|
0
|
public boolean isGreater(IHasOrder aData) {
|
85
|
0
|
double d = ((IDoubleData)aData).getDouble();
|
86
|
0
|
return myValue > d;
|
87
|
|
}
|
88
|
|
|
89
|
0
|
public boolean isGreaterOrEqual(IHasOrder aData) {
|
90
|
0
|
double d = ((IDoubleData)aData).getDouble();
|
91
|
0
|
return myValue >= d;
|
92
|
|
}
|
93
|
|
|
94
|
0
|
public boolean isLess(IHasOrder aData) {
|
95
|
0
|
double d = ((IDoubleData)aData).getDouble();
|
96
|
0
|
return myValue < d;
|
97
|
|
}
|
98
|
|
|
99
|
0
|
public boolean isLessOrEqual(IHasOrder aData) {
|
100
|
0
|
double d = ((IDoubleData)aData).getDouble();
|
101
|
0
|
return myValue <= d;
|
102
|
|
}
|
103
|
|
|
104
|
|
}
|
105
|
|
|