Skip to content

Commit a60f614

Browse files
committed
2 parents 481cb16 + 58170f0 commit a60f614

File tree

21 files changed

+364
-31
lines changed

21 files changed

+364
-31
lines changed

epics-util/src/main/java/org/epics/util/stats/Range.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,16 @@ public int hashCode() {
213213
* @return the range
214214
*/
215215
public static Range of(final double minValue, final double maxValue) {
216-
if (Double.isNaN(minValue) || Double.isNaN(maxValue)) {
216+
if (Double.isNaN(minValue) && Double.isNaN(maxValue)) {
217217
return Range.UNDEFINED;
218218
}
219-
219+
else if (Double.isNaN(minValue)) {
220+
return new Range(Double.NEGATIVE_INFINITY, maxValue, false);
221+
}
222+
else if (Double.isNaN(maxValue)) {
223+
return new Range(minValue, Double.POSITIVE_INFINITY, false);
224+
}
225+
220226
if (minValue > maxValue) {
221227
return new Range(maxValue, minValue, true);
222228
}

epics-util/src/test/java/org/epics/util/stats/RangeTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ public void range3() throws Exception {
4444
@Test
4545
public void range4() throws Exception {
4646
Range range = Range.of(0.0, Double.NaN);
47-
assertThat(range, sameInstance(Range.undefined()));
47+
assertThat(range.getMinimum(), equalTo(0.0));
48+
assertThat(range.getMaximum(), equalTo(Double.POSITIVE_INFINITY));
49+
assertThat(range.isReversed(), equalTo(false));
50+
assertThat(range.toString(), equalTo("[0.0 - Infinity]"));
4851
}
4952

5053
@Test

epics-vtype/vtype-gson/src/main/java/org/epics/vtype/gson/GsonVTypeBuilder.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ public GsonVTypeBuilder addDisplay(Display display) {
163163
.addIgnoreNaN("lowWarning", display.getWarningRange().getMinimum())
164164
.addIgnoreNaN("highWarning", display.getWarningRange().getMaximum())
165165
.add("units", display.getUnit())
166+
.addNullableObject("description", display.getDescription())
166167
.build());
167168
}
168169

@@ -242,6 +243,8 @@ public GsonVTypeBuilder addObject(String string, Object o) {
242243
addListNumber(string, (ListNumber) o);
243244
} else if (o instanceof ListBoolean) {
244245
addListBoolean(string, (ListBoolean) o);
246+
} else if (o instanceof String) {
247+
add(string, (String)o);
245248
} else {
246249
throw new UnsupportedOperationException("Class " + o.getClass() + " not supported");
247250
}

epics-vtype/vtype-gson/src/main/java/org/epics/vtype/gson/VTypeGsonMapper.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ public Display getDisplay() {
116116
Range.of(display.getNotNullDouble("lowAlarm"), display.getNotNullDouble("highAlarm")),
117117
Range.of(display.getNotNullDouble("lowWarning"), display.getNotNullDouble("highWarning")),
118118
Range.of(display.getNotNullDouble("lowControl"), display.getNotNullDouble("highControl")),
119-
display.getString("units"), new DecimalFormat());
119+
display.getString("units"), new DecimalFormat(),
120+
display.getString("description", null));
120121
}
121122

122123
public ListDouble getListDouble(String string) {
@@ -280,7 +281,7 @@ public String getString(String string) {
280281
}
281282

282283
public String getString(String string, String string1) {
283-
return json.get(string).isJsonNull() ? string1 : json.get(string).getAsString();
284+
return (json.get(string) == null || json.get(string).isJsonNull()) ? string1 : json.get(string).getAsString();
284285
}
285286

286287
public int getInt(String string) {

epics-vtype/vtype-gson/src/test/java/org/epics/vtype/gson/VTypeToGsonTest.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import java.io.IOException;
1010
import java.io.InputStream;
1111
import java.io.InputStreamReader;
12+
import java.text.DecimalFormat;
13+
import java.text.NumberFormat;
1214
import java.time.Instant;
1315
import java.util.ArrayList;
1416
import java.util.Arrays;
@@ -32,6 +34,7 @@
3234
import org.epics.util.number.UInteger;
3335
import org.epics.util.number.ULong;
3436
import org.epics.util.number.UShort;
37+
import org.epics.util.stats.Range;
3538
import org.epics.vtype.Alarm;
3639
import org.epics.vtype.AlarmSeverity;
3740
import org.epics.vtype.AlarmStatus;
@@ -135,6 +138,35 @@ public void vDouble1() {
135138
testDeserialization("VDouble1a", vDouble1);
136139
}
137140

141+
@Test
142+
public void vDouble1b() {
143+
VDouble vDouble1 = VDouble.of(3.14, Alarm.of(AlarmSeverity.MINOR,
144+
AlarmStatus.DB, "LOW"),
145+
Time.of(Instant.ofEpochSecond(0, 0)),
146+
Display.of(Range.of(-100.0, 100.0), Range.of(-100.0, 100.0), Range.of(-10.0, 10.0), Range.of(Double.NaN, Double.NaN), "degC", new DecimalFormat(), null));
147+
testSerialization(vDouble1, "VDouble1b");
148+
testDeserialization("VDouble1b", vDouble1);
149+
}
150+
151+
@Test
152+
public void vDouble1c() {
153+
VDouble vDouble1 = VDouble.of(3.14, Alarm.of(AlarmSeverity.MINOR,
154+
AlarmStatus.DB, "LOW"),
155+
Time.of(Instant.ofEpochSecond(0, 0)),
156+
Display.of(Range.of(-100.0, 100.0), Range.of(-100.0, 100.0), Range.of(-10.0, 10.0), Range.of(Double.NaN, Double.NaN), "degC", new DecimalFormat(), "fooBar"));
157+
testSerialization(vDouble1, "VDouble1c");
158+
testDeserialization("VDouble1c", vDouble1);
159+
}
160+
161+
162+
@Test
163+
public void vDouble2() {
164+
VDouble vDouble1 = VDouble.of(3.14, Alarm.of(AlarmSeverity.MINOR, AlarmStatus.DB, "LOW"), Time.of(Instant.ofEpochSecond(0, 0)), Display.none());
165+
testSerialization(vDouble1, "VDouble1");
166+
testDeserialization("VDouble1", vDouble1);
167+
testDeserialization("VDouble1a", vDouble1);
168+
}
169+
138170
@Test
139171
public void vFloat1() {
140172
VFloat vFloat1 = VFloat.of((float) 3.125, Alarm.of(AlarmSeverity.MINOR, AlarmStatus.DB, "HIGH"), Time.of(Instant.ofEpochSecond(0, 0)), Display.none());
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"type":{
3+
"name":"VDouble",
4+
"version":1
5+
},
6+
"value":3.14,
7+
"alarm":{
8+
"severity":"MINOR",
9+
"status":"DB",
10+
"name":"LOW"
11+
},
12+
"time":{
13+
"unixSec":0,
14+
"nanoSec":0
15+
},
16+
"display":{
17+
"lowAlarm":-100.0,
18+
"highAlarm":100.0,
19+
"lowDisplay":-100.0,
20+
"highDisplay":100.0,
21+
"lowWarning":-10.0,
22+
"highWarning":10.0,
23+
"units":"degC"
24+
}
25+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"type":{
3+
"name":"VDouble",
4+
"version":1
5+
},
6+
"value":3.14,
7+
"alarm":{
8+
"severity":"MINOR",
9+
"status":"DB",
10+
"name":"LOW"
11+
},
12+
"time":{
13+
"unixSec":0,
14+
"nanoSec":0
15+
},
16+
"display":{
17+
"lowAlarm":-100.0,
18+
"highAlarm":100.0,
19+
"lowDisplay":-100.0,
20+
"highDisplay":100.0,
21+
"lowWarning":-10.0,
22+
"highWarning":10.0,
23+
"units":"degC",
24+
"description": "fooBar"
25+
}
26+
}

epics-vtype/vtype-json/src/main/java/org/epics/vtype/json/JsonVTypeBuilder.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ public JsonVTypeBuilder addDisplay(Display display) {
147147
.addIgnoreNaN("highDisplay", display.getDisplayRange().getMaximum())
148148
.addIgnoreNaN("lowWarning", display.getWarningRange().getMinimum())
149149
.addIgnoreNaN("highWarning", display.getWarningRange().getMaximum())
150-
.add("units", display.getUnit()));
150+
.add("units", display.getUnit())
151+
.addNullableObject("description", display.getDescription()));
151152
}
152153

153154
public JsonVTypeBuilder addEnum(VEnum en) {
@@ -225,6 +226,8 @@ public JsonVTypeBuilder addObject(String string, Object o) {
225226
addListNumber(string, (ListNumber) o);
226227
} else if (o instanceof ListBoolean) {
227228
addListBoolean(string, (ListBoolean) o);
229+
} else if (o instanceof String){
230+
add(string, (String)o);
228231
} else {
229232
throw new UnsupportedOperationException("Class " + o.getClass() + " not supported");
230233
}

epics-vtype/vtype-json/src/main/java/org/epics/vtype/json/VTypeJsonMapper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ public Display getDisplay() {
100100
Range.of(display.getNotNullDouble("lowAlarm"), display.getNotNullDouble("highAlarm")),
101101
Range.of(display.getNotNullDouble("lowWarning"), display.getNotNullDouble("highWarning")),
102102
Range.of(display.getNotNullDouble("lowControl"), display.getNotNullDouble("highControl")),
103-
display.getString("units"), new DecimalFormat());
103+
display.getString("units"), new DecimalFormat(),
104+
display.getString("description", null));
104105
}
105106

106107
public ListDouble getListDouble(String string) {

epics-vtype/vtype-json/src/test/java/org/epics/vtype/json/VTypeToJsonTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.io.FileWriter;
99
import java.io.IOException;
1010
import java.io.StringWriter;
11+
import java.text.DecimalFormat;
1112
import java.time.Instant;
1213
import java.util.ArrayList;
1314
import java.util.Arrays;
@@ -32,6 +33,7 @@
3233
import org.epics.util.number.UInteger;
3334
import org.epics.util.number.ULong;
3435
import org.epics.util.number.UShort;
36+
import org.epics.util.stats.Range;
3537
import org.epics.vtype.Alarm;
3638
import org.epics.vtype.AlarmSeverity;
3739
import org.epics.vtype.AlarmStatus;
@@ -134,6 +136,26 @@ public void vDouble1() {
134136
testDeserialization("VDouble1", vDouble1);
135137
testDeserialization("VDouble1a", vDouble1);
136138
}
139+
140+
@Test
141+
public void vDouble1b() {
142+
VDouble vDouble1 = VDouble.of(3.14, Alarm.of(AlarmSeverity.MINOR,
143+
AlarmStatus.DB, "LOW"),
144+
Time.of(Instant.ofEpochSecond(0, 0)),
145+
Display.of(Range.of(-100.0, 100.0), Range.of(-100.0, 100.0), Range.of(-10.0, 10.0), Range.of(Double.NaN, Double.NaN), "degC", new DecimalFormat(), null));
146+
testSerialization(vDouble1, "VDouble1b");
147+
testDeserialization("VDouble1b", vDouble1);
148+
}
149+
150+
@Test
151+
public void vDouble1c() {
152+
VDouble vDouble1 = VDouble.of(3.14, Alarm.of(AlarmSeverity.MINOR,
153+
AlarmStatus.DB, "LOW"),
154+
Time.of(Instant.ofEpochSecond(0, 0)),
155+
Display.of(Range.of(-100.0, 100.0), Range.of(-100.0, 100.0), Range.of(-10.0, 10.0), Range.of(Double.NaN, Double.NaN), "degC", new DecimalFormat(), "fooBar"));
156+
testSerialization(vDouble1, "VDouble1c");
157+
testDeserialization("VDouble1c", vDouble1);
158+
}
137159

138160
@Test
139161
public void vFloat1() {

0 commit comments

Comments
 (0)