Skip to content

Commit

Permalink
Merge pull request #5373 from entur/minor_performance_fixes
Browse files Browse the repository at this point in the history
Minor performance fixes
  • Loading branch information
vpaturet authored Sep 27, 2023
2 parents 5535ca6 + ae46416 commit 5085fb3
Show file tree
Hide file tree
Showing 16 changed files with 17 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public boolean equals(Object thatObject) {
return false;
}
StopPatternServiceDateKey that = (StopPatternServiceDateKey) thatObject;
return (this.stopPattern.equals(that.stopPattern) & this.serviceDate.equals(that.serviceDate));
return (this.stopPattern.equals(that.stopPattern) && this.serviceDate.equals(that.serviceDate));
}
}

Expand All @@ -215,6 +215,6 @@ public boolean equals(Object thatObject) {
return false;
}
TripServiceDateKey that = (TripServiceDateKey) thatObject;
return (this.trip.equals(that.trip) & this.serviceDate.equals(that.serviceDate));
return (this.trip.equals(that.trip) && this.serviceDate.equals(that.serviceDate));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private List<VehicleParking> parseJSON(

JsonNode rootNode = mapper.readTree(facilitiesString);

if (!jsonParsePath.equals("")) {
if (!jsonParsePath.isEmpty()) {
String delimiter = "/";
String[] parseElement = jsonParsePath.split(delimiter);
for (String s : parseElement) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public Map<FeedScopedId, VehicleParkingGroup> parseHub(JsonNode jsonNode) {
.fieldNames()
.forEachRemaining(lang -> {
String name = nameNode.path(lang).asText();
if (!name.equals("")) {
if (!name.isEmpty()) {
translations.put(lang, nameNode.path(lang).asText());
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private Map<FeedScopedId, VehicleParkingGroup> parseJSON(InputStream dataStream)

JsonNode rootNode = mapper.readTree(hubsString);

if (!jsonParsePath.equals("")) {
if (!jsonParsePath.isEmpty()) {
String delimiter = "/";
String[] parseElement = jsonParsePath.split(delimiter);
for (String s : parseElement) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public VehicleParking parsePark(
.fieldNames()
.forEachRemaining(lang -> {
String name = nameNode.path(lang).asText();
if (!name.equals("")) {
if (!name.isEmpty()) {
translations.put(lang, nameNode.path(lang).asText());
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public static Geometry convertGeoJsonToJtsGeometry(GeoJsonObject geoJsonGeom)
int i = 0;
for (List<LngLatAlt> geoJsonPath : geoJsonMultiLineString.getCoordinates()) {
org.geojson.LineString geoJsonLineString = new org.geojson.LineString(
geoJsonPath.toArray(new LngLatAlt[geoJsonPath.size()])
geoJsonPath.toArray(new LngLatAlt[0])
);
jtsLineStrings[i++] = (LineString) convertGeoJsonToJtsGeometry(geoJsonLineString);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private List<T> parseJSON(InputStream dataStream) throws IllegalArgumentExceptio
ObjectMapper mapper = new ObjectMapper();
JsonNode rootNode = mapper.readTree(rentalString);

if (!jsonParsePath.equals("")) {
if (!jsonParsePath.isEmpty()) {
String delimiter = "/";
String[] parseElement = jsonParsePath.split(delimiter);
for (String s : parseElement) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public List<LineString> createHopGeometries(Trip trip) {
if (
trip.getShapeId() == null ||
trip.getShapeId().getId() == null ||
trip.getShapeId().getId().equals("")
trip.getShapeId().getId().isEmpty()
) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,7 @@ public void buildGraph() {
areas.add(ae.getArea());
}
for (AreaEdgeList a : areas) {
for (Vertex v : a.visibilityVertices()) {
visibilityVertices.add(v);
}
visibilityVertices.addAll(a.visibilityVertices());
}

int removed = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ public AreaGroup(Collection<Area> areas) {
}
}
GeometryFactory geometryFactory = GeometryUtils.getGeometryFactory();
Geometry allPolygons = geometryFactory.createMultiPolygon(
allRings.toArray(new Polygon[allRings.size()])
);
Geometry allPolygons = geometryFactory.createMultiPolygon(allRings.toArray(new Polygon[0]));
this.union = allPolygons.union();

if (this.union instanceof GeometryCollection coll) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private Polygon calculateJtsPolygon() {
lrholelist.add(ring);
}
}
LinearRing[] lrholes = lrholelist.toArray(new LinearRing[lrholelist.size()]);
LinearRing[] lrholes = lrholelist.toArray(new LinearRing[0]);
return factory.createPolygon(shell, lrholes);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public Optional<EdgeVisualAttributes> renderEdge(Edge e) {
label += " car";
colorIndex += 4;
}
if (!label.equals("")) {
if (!label.isEmpty()) {
label = "No" + label + " thru traffic";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static OSMLevel fromString(
/* get short and long level names by splitting on = character */
String shortName = "";
String longName = "";
Integer indexEquals = spec.indexOf('=');
int indexEquals = spec.indexOf('=');
if (indexEquals >= 1) {
shortName = spec.substring(0, indexEquals);
longName = spec.substring(indexEquals + 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ public Float getMetersSecondFromSpeed(String speed) {
}

String units = m.group(2);
if (units == null || units.equals("")) units = "kmh";
if (units == null || units.isEmpty()) units = "kmh";

// we'll be doing quite a few string comparisons here
units = units.intern();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ public static class PositiveInteger implements IParameterValidator {

@Override
public void validate(String name, String value) throws ParameterException {
Integer i = Integer.parseInt(value);
int i = Integer.parseInt(value);
if (i <= 0) {
String msg = String.format("%s must be a positive integer.", name);
throw new ParameterException(msg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ public void testCompareHeaps() throws InterruptedException {
// First determine the expected results using a plain old PriorityQueue
expected = new ArrayList<>(N);
PriorityQueue<Integer> q = new PriorityQueue<>(N);
for (Integer j : input) {
q.add(j);
}
q.addAll(input);
while (!q.isEmpty()) {
expected.add(q.remove());
}
Expand Down

0 comments on commit 5085fb3

Please sign in to comment.