Skip to content

Commit 614da4f

Browse files
authored
Merge pull request #3054 from ControlSystemStudio/refactor_guava
Replacing use of guava ImmutableLists with Collections.unmodifiableList
2 parents 54b79c4 + 5b5ed1f commit 614da4f

File tree

4 files changed

+45
-52
lines changed

4 files changed

+45
-52
lines changed

app/databrowser-json/pom.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,6 @@
3939
<version>${jackson.version}</version>
4040
</dependency>
4141

42-
<dependency>
43-
<groupId>com.google.guava</groupId>
44-
<artifactId>guava</artifactId>
45-
<version>${guava.version}</version>
46-
</dependency>
47-
4842
<dependency>
4943
<groupId>org.epics</groupId>
5044
<artifactId>epics-util</artifactId>

app/databrowser-json/src/main/java/org/phoebus/archive/reader/json/internal/JsonVTypeReader.java

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111
import com.fasterxml.jackson.core.JsonParseException;
1212
import com.fasterxml.jackson.core.JsonParser;
1313
import com.fasterxml.jackson.core.JsonToken;
14-
import com.google.common.primitives.ImmutableDoubleArray;
15-
import com.google.common.primitives.ImmutableIntArray;
16-
import com.google.common.primitives.ImmutableLongArray;
17-
import org.epics.util.array.CollectionNumbers;
1814
import org.epics.util.array.ListDouble;
1915
import org.epics.util.array.ListInteger;
2016
import org.epics.util.array.ListLong;
@@ -43,6 +39,8 @@
4339
import java.math.BigInteger;
4440
import java.text.NumberFormat;
4541
import java.time.Instant;
42+
import java.util.ArrayList;
43+
import java.util.Collections;
4644
import java.util.LinkedList;
4745
import java.util.List;
4846
import java.util.Locale;
@@ -103,12 +101,12 @@ public static VType readValue(
103101
parser.getTokenLocation());
104102
}
105103
Display display = null;
106-
ImmutableDoubleArray double_value = null;
104+
List<Double> double_value = null;
107105
EnumDisplay enum_display = null;
108-
ImmutableIntArray enum_value = null;
106+
List<Integer> enum_value = null;
109107
String field_name = null;
110108
boolean found_value = false;
111-
ImmutableLongArray long_value = null;
109+
List<Long> long_value = null;
112110
Double maximum = null;
113111
Double minimum = null;
114112
String quality = null;
@@ -280,13 +278,12 @@ public static VType readValue(
280278
if (display == null) {
281279
display = Display.none();
282280
}
283-
if (double_value.length() == 1) {
281+
if (double_value.size() == 1) {
284282
return VDouble.of(
285283
double_value.get(0), alarm, time, display);
286284
} else {
287285
return VDoubleArray.of(
288-
CollectionNumbers.toListDouble(
289-
double_value.toArray()),
286+
toListDouble(double_value),
290287
alarm,
291288
time,
292289
display);
@@ -296,7 +293,7 @@ public static VType readValue(
296293
// Ensure that we have labels for all indices.
297294
int min_value = Integer.MAX_VALUE;
298295
int max_value = Integer.MIN_VALUE;
299-
for (var i = 0; i < enum_value.length(); ++i) {
296+
for (var i = 0; i < enum_value.size(); ++i) {
300297
final var value = enum_value.get(i);
301298
min_value = Math.min(min_value, value);
302299
max_value = Math.max(max_value, value);
@@ -321,7 +318,7 @@ public static VType readValue(
321318
Range.undefined(),
322319
"",
323320
NumberFormats.precisionFormat(0));
324-
if (enum_value.length() == 1) {
321+
if (enum_value.size() == 1) {
325322
return VInt.of(
326323
enum_value.get(0),
327324
alarm,
@@ -335,7 +332,7 @@ public static VType readValue(
335332
display);
336333
}
337334
}
338-
if (enum_value.length() == 1) {
335+
if (enum_value.size() == 1) {
339336
return VEnum.of(
340337
enum_value.get(0), enum_display, alarm, time);
341338
} else {
@@ -366,7 +363,7 @@ display. getAlarmRange(),
366363
NumberFormats.precisionFormat(0),
367364
display.getDescription());
368365
}
369-
if (long_value.length() == 1) {
366+
if (long_value.size() == 1) {
370367
return VLong.of(long_value.get(0), alarm, time, display);
371368
} else {
372369
return VLongArray.of(
@@ -386,7 +383,7 @@ display. getAlarmRange(),
386383
"Mandatory field is missing in object.",
387384
parser.getTokenLocation());
388385
}
389-
if (double_value.length() == 1) {
386+
if (double_value.size() == 1) {
390387
return VStatistics.of(
391388
double_value.get(0),
392389
Double.NaN,
@@ -459,9 +456,10 @@ private static boolean readBooleanValue(final JsonParser parser)
459456
return parser.getBooleanValue();
460457
}
461458

462-
private static ImmutableDoubleArray readDoubleArray(
459+
private static List<Double> readDoubleArray(
463460
final JsonParser parser) throws IOException {
464-
final var array_builder = ImmutableDoubleArray.builder(1);
461+
462+
final List<Double> values = new ArrayList<>();
465463
var token = parser.getCurrentToken();
466464
if (token != JsonToken.START_ARRAY) {
467465
throw new JsonParseException(
@@ -477,9 +475,9 @@ private static ImmutableDoubleArray readDoubleArray(
477475
if (token == JsonToken.END_ARRAY) {
478476
break;
479477
}
480-
array_builder.add(readDoubleValue(parser));
478+
values.add(readDoubleValue(parser));
481479
}
482-
return array_builder.build();
480+
return Collections.unmodifiableList(values);
483481
}
484482

485483
private static double readDoubleValue(final JsonParser parser)
@@ -515,9 +513,9 @@ private static Instant readInstant(final JsonParser parser)
515513
return bigIntegerToTimestamp(parser.getBigIntegerValue());
516514
}
517515

518-
private static ImmutableIntArray readIntArray(final JsonParser parser)
516+
private static List<Integer> readIntArray(final JsonParser parser)
519517
throws IOException {
520-
final var array_builder = ImmutableIntArray.builder(1);
518+
final List<Integer> values = new ArrayList<>();
521519
var token = parser.getCurrentToken();
522520
if (token != JsonToken.START_ARRAY) {
523521
throw new JsonParseException(
@@ -533,9 +531,9 @@ private static ImmutableIntArray readIntArray(final JsonParser parser)
533531
if (token == JsonToken.END_ARRAY) {
534532
break;
535533
}
536-
array_builder.add(readIntValue(parser));
534+
values.add(readIntValue(parser));
537535
}
538-
return array_builder.build();
536+
return Collections.unmodifiableList(values);
539537
}
540538

541539
private static int readIntValue(final JsonParser parser)
@@ -551,9 +549,9 @@ private static int readIntValue(final JsonParser parser)
551549
return parser.getIntValue();
552550
}
553551

554-
private static ImmutableLongArray readLongArray(final JsonParser parser)
552+
private static List<Long> readLongArray(final JsonParser parser)
555553
throws IOException {
556-
final var array_builder = ImmutableLongArray.builder(1);
554+
final List<Long> values = new ArrayList<>();
557555
var token = parser.getCurrentToken();
558556
if (token != JsonToken.START_ARRAY) {
559557
throw new JsonParseException(
@@ -569,9 +567,9 @@ private static ImmutableLongArray readLongArray(final JsonParser parser)
569567
if (token == JsonToken.END_ARRAY) {
570568
break;
571569
}
572-
array_builder.add(readLongValue(parser));
570+
values.add(readLongValue(parser));
573571
}
574-
return array_builder.build();
572+
return Collections.unmodifiableList(values);
575573
}
576574

577575
private static long readLongValue(final JsonParser parser)
@@ -888,7 +886,7 @@ private static double stringToSpecialDouble(
888886
};
889887
}
890888

891-
private static ListDouble toListDouble(final ImmutableDoubleArray array) {
889+
private static ListDouble toListDouble(final List<Double> array) {
892890
return new ListDouble() {
893891
@Override
894892
public double getDouble(int index) {
@@ -897,12 +895,12 @@ public double getDouble(int index) {
897895

898896
@Override
899897
public int size() {
900-
return array.length();
898+
return array.size();
901899
}
902900
};
903901
}
904902

905-
private static ListInteger toListInteger(final ImmutableIntArray array) {
903+
private static ListInteger toListInteger(final List<Integer> array) {
906904
return new ListInteger() {
907905
@Override
908906
public int getInt(int index) {
@@ -911,12 +909,12 @@ public int getInt(int index) {
911909

912910
@Override
913911
public int size() {
914-
return array.length();
912+
return array.size();
915913
}
916914
};
917915
}
918916

919-
private static ListLong toListLong(final ImmutableLongArray array) {
917+
private static ListLong toListLong(final List<Long> array) {
920918
return new ListLong() {
921919
@Override
922920
public long getLong(int index) {
@@ -925,7 +923,7 @@ public long getLong(int index) {
925923

926924
@Override
927925
public int size() {
928-
return array.length();
926+
return array.size();
929927
}
930928
};
931929
}

app/databrowser-json/src/test/java/org/phoebus/archive/reader/json/HttpServerTestBase.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
package org.phoebus.archive.reader.json;
1010

11-
import com.google.common.base.Splitter;
12-
import com.google.common.collect.Maps;
1311
import com.sun.net.httpserver.Headers;
1412
import com.sun.net.httpserver.HttpHandler;
1513
import com.sun.net.httpserver.HttpServer;
@@ -23,10 +21,12 @@
2321
import java.net.URI;
2422
import java.net.URLDecoder;
2523
import java.nio.charset.StandardCharsets;
24+
import java.util.Arrays;
2625
import java.util.LinkedList;
2726
import java.util.List;
2827
import java.util.Map;
2928
import java.util.function.Consumer;
29+
import java.util.stream.Collectors;
3030

3131
/**
3232
* Base class for tests that need an HTTP server.
@@ -62,12 +62,18 @@ public record HttpRequest(
6262
*/
6363
public static Map<String, String> parseQueryString(
6464
final String query_string) {
65-
return Maps.transformValues(
66-
Splitter
67-
.on('&')
68-
.withKeyValueSeparator('=')
69-
.split(query_string),
70-
(value) -> URLDecoder.decode(value, StandardCharsets.UTF_8));
65+
66+
return Arrays.stream(query_string.split("&"))
67+
.collect(Collectors.toMap(
68+
k -> k.split("=")[0],
69+
k -> URLDecoder.decode(k.split("=")[1], StandardCharsets.UTF_8)));
70+
//
71+
// return Maps.transformValues(
72+
// Splitter
73+
// .on('&')
74+
// .withKeyValueSeparator('=')
75+
// .split(query_string),
76+
// (value) -> URLDecoder.decode(value, StandardCharsets.UTF_8));
7177
}
7278

7379
/**

dependencies/phoebus-target/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,6 @@
217217
<artifactId>javax.activation</artifactId>
218218
<version>1.2.0</version>
219219
</dependency>
220-
<dependency>
221-
<groupId>com.google.guava</groupId>
222-
<artifactId>guava</artifactId>
223-
<version>${guava.version}</version>
224-
</dependency>
225220
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
226221
<dependency>
227222
<groupId>com.fasterxml.jackson.core</groupId>

0 commit comments

Comments
 (0)