Skip to content

Commit

Permalink
Merge pull request #3054 from ControlSystemStudio/refactor_guava
Browse files Browse the repository at this point in the history
Replacing use of guava ImmutableLists with Collections.unmodifiableList
  • Loading branch information
shroffk authored Jun 18, 2024
2 parents 54b79c4 + 5b5ed1f commit 614da4f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 52 deletions.
6 changes: 0 additions & 6 deletions app/databrowser-json/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@
<version>${jackson.version}</version>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>

<dependency>
<groupId>org.epics</groupId>
<artifactId>epics-util</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.google.common.primitives.ImmutableDoubleArray;
import com.google.common.primitives.ImmutableIntArray;
import com.google.common.primitives.ImmutableLongArray;
import org.epics.util.array.CollectionNumbers;
import org.epics.util.array.ListDouble;
import org.epics.util.array.ListInteger;
import org.epics.util.array.ListLong;
Expand Down Expand Up @@ -43,6 +39,8 @@
import java.math.BigInteger;
import java.text.NumberFormat;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -103,12 +101,12 @@ public static VType readValue(
parser.getTokenLocation());
}
Display display = null;
ImmutableDoubleArray double_value = null;
List<Double> double_value = null;
EnumDisplay enum_display = null;
ImmutableIntArray enum_value = null;
List<Integer> enum_value = null;
String field_name = null;
boolean found_value = false;
ImmutableLongArray long_value = null;
List<Long> long_value = null;
Double maximum = null;
Double minimum = null;
String quality = null;
Expand Down Expand Up @@ -280,13 +278,12 @@ public static VType readValue(
if (display == null) {
display = Display.none();
}
if (double_value.length() == 1) {
if (double_value.size() == 1) {
return VDouble.of(
double_value.get(0), alarm, time, display);
} else {
return VDoubleArray.of(
CollectionNumbers.toListDouble(
double_value.toArray()),
toListDouble(double_value),
alarm,
time,
display);
Expand All @@ -296,7 +293,7 @@ public static VType readValue(
// Ensure that we have labels for all indices.
int min_value = Integer.MAX_VALUE;
int max_value = Integer.MIN_VALUE;
for (var i = 0; i < enum_value.length(); ++i) {
for (var i = 0; i < enum_value.size(); ++i) {
final var value = enum_value.get(i);
min_value = Math.min(min_value, value);
max_value = Math.max(max_value, value);
Expand All @@ -321,7 +318,7 @@ public static VType readValue(
Range.undefined(),
"",
NumberFormats.precisionFormat(0));
if (enum_value.length() == 1) {
if (enum_value.size() == 1) {
return VInt.of(
enum_value.get(0),
alarm,
Expand All @@ -335,7 +332,7 @@ public static VType readValue(
display);
}
}
if (enum_value.length() == 1) {
if (enum_value.size() == 1) {
return VEnum.of(
enum_value.get(0), enum_display, alarm, time);
} else {
Expand Down Expand Up @@ -366,7 +363,7 @@ display. getAlarmRange(),
NumberFormats.precisionFormat(0),
display.getDescription());
}
if (long_value.length() == 1) {
if (long_value.size() == 1) {
return VLong.of(long_value.get(0), alarm, time, display);
} else {
return VLongArray.of(
Expand All @@ -386,7 +383,7 @@ display. getAlarmRange(),
"Mandatory field is missing in object.",
parser.getTokenLocation());
}
if (double_value.length() == 1) {
if (double_value.size() == 1) {
return VStatistics.of(
double_value.get(0),
Double.NaN,
Expand Down Expand Up @@ -459,9 +456,10 @@ private static boolean readBooleanValue(final JsonParser parser)
return parser.getBooleanValue();
}

private static ImmutableDoubleArray readDoubleArray(
private static List<Double> readDoubleArray(
final JsonParser parser) throws IOException {
final var array_builder = ImmutableDoubleArray.builder(1);

final List<Double> values = new ArrayList<>();
var token = parser.getCurrentToken();
if (token != JsonToken.START_ARRAY) {
throw new JsonParseException(
Expand All @@ -477,9 +475,9 @@ private static ImmutableDoubleArray readDoubleArray(
if (token == JsonToken.END_ARRAY) {
break;
}
array_builder.add(readDoubleValue(parser));
values.add(readDoubleValue(parser));
}
return array_builder.build();
return Collections.unmodifiableList(values);
}

private static double readDoubleValue(final JsonParser parser)
Expand Down Expand Up @@ -515,9 +513,9 @@ private static Instant readInstant(final JsonParser parser)
return bigIntegerToTimestamp(parser.getBigIntegerValue());
}

private static ImmutableIntArray readIntArray(final JsonParser parser)
private static List<Integer> readIntArray(final JsonParser parser)
throws IOException {
final var array_builder = ImmutableIntArray.builder(1);
final List<Integer> values = new ArrayList<>();
var token = parser.getCurrentToken();
if (token != JsonToken.START_ARRAY) {
throw new JsonParseException(
Expand All @@ -533,9 +531,9 @@ private static ImmutableIntArray readIntArray(final JsonParser parser)
if (token == JsonToken.END_ARRAY) {
break;
}
array_builder.add(readIntValue(parser));
values.add(readIntValue(parser));
}
return array_builder.build();
return Collections.unmodifiableList(values);
}

private static int readIntValue(final JsonParser parser)
Expand All @@ -551,9 +549,9 @@ private static int readIntValue(final JsonParser parser)
return parser.getIntValue();
}

private static ImmutableLongArray readLongArray(final JsonParser parser)
private static List<Long> readLongArray(final JsonParser parser)
throws IOException {
final var array_builder = ImmutableLongArray.builder(1);
final List<Long> values = new ArrayList<>();
var token = parser.getCurrentToken();
if (token != JsonToken.START_ARRAY) {
throw new JsonParseException(
Expand All @@ -569,9 +567,9 @@ private static ImmutableLongArray readLongArray(final JsonParser parser)
if (token == JsonToken.END_ARRAY) {
break;
}
array_builder.add(readLongValue(parser));
values.add(readLongValue(parser));
}
return array_builder.build();
return Collections.unmodifiableList(values);
}

private static long readLongValue(final JsonParser parser)
Expand Down Expand Up @@ -888,7 +886,7 @@ private static double stringToSpecialDouble(
};
}

private static ListDouble toListDouble(final ImmutableDoubleArray array) {
private static ListDouble toListDouble(final List<Double> array) {
return new ListDouble() {
@Override
public double getDouble(int index) {
Expand All @@ -897,12 +895,12 @@ public double getDouble(int index) {

@Override
public int size() {
return array.length();
return array.size();
}
};
}

private static ListInteger toListInteger(final ImmutableIntArray array) {
private static ListInteger toListInteger(final List<Integer> array) {
return new ListInteger() {
@Override
public int getInt(int index) {
Expand All @@ -911,12 +909,12 @@ public int getInt(int index) {

@Override
public int size() {
return array.length();
return array.size();
}
};
}

private static ListLong toListLong(final ImmutableLongArray array) {
private static ListLong toListLong(final List<Long> array) {
return new ListLong() {
@Override
public long getLong(int index) {
Expand All @@ -925,7 +923,7 @@ public long getLong(int index) {

@Override
public int size() {
return array.length();
return array.size();
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

package org.phoebus.archive.reader.json;

import com.google.common.base.Splitter;
import com.google.common.collect.Maps;
import com.sun.net.httpserver.Headers;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
Expand All @@ -23,10 +21,12 @@
import java.net.URI;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import java.util.stream.Collectors;

/**
* Base class for tests that need an HTTP server.
Expand Down Expand Up @@ -62,12 +62,18 @@ public record HttpRequest(
*/
public static Map<String, String> parseQueryString(
final String query_string) {
return Maps.transformValues(
Splitter
.on('&')
.withKeyValueSeparator('=')
.split(query_string),
(value) -> URLDecoder.decode(value, StandardCharsets.UTF_8));

return Arrays.stream(query_string.split("&"))
.collect(Collectors.toMap(
k -> k.split("=")[0],
k -> URLDecoder.decode(k.split("=")[1], StandardCharsets.UTF_8)));
//
// return Maps.transformValues(
// Splitter
// .on('&')
// .withKeyValueSeparator('=')
// .split(query_string),
// (value) -> URLDecoder.decode(value, StandardCharsets.UTF_8));
}

/**
Expand Down
5 changes: 0 additions & 5 deletions dependencies/phoebus-target/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,6 @@
<artifactId>javax.activation</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
Expand Down

0 comments on commit 614da4f

Please sign in to comment.