diff --git a/planetiler-benchmarks/src/main/java/com/onthegomap/planetiler/benchmarks/BenchmarkMbtilesRead.java b/planetiler-benchmarks/src/main/java/com/onthegomap/planetiler/benchmarks/BenchmarkMbtilesRead.java index b9255ffa74..e0a19f94a7 100644 --- a/planetiler-benchmarks/src/main/java/com/onthegomap/planetiler/benchmarks/BenchmarkMbtilesRead.java +++ b/planetiler-benchmarks/src/main/java/com/onthegomap/planetiler/benchmarks/BenchmarkMbtilesRead.java @@ -47,7 +47,7 @@ public static void main(String[] args) throws Exception { List randomCoordsToFetchPerRepetition = new LinkedList<>(); do { - try (var db = Mbtiles.newReadOnlyDatabase(mbtilesPaths.get(0))) { + try (var db = Mbtiles.newReadOnlyDatabase(mbtilesPaths.getFirst())) { try (var statement = db.connection().prepareStatement(SELECT_RANDOM_COORDS)) { statement.setInt(1, nrTileReads - randomCoordsToFetchPerRepetition.size()); var rs = statement.executeQuery(); diff --git a/planetiler-core/src/main/java/com/onthegomap/planetiler/FeatureMerge.java b/planetiler-core/src/main/java/com/onthegomap/planetiler/FeatureMerge.java index 202178d8e1..d272cf11eb 100644 --- a/planetiler-core/src/main/java/com/onthegomap/planetiler/FeatureMerge.java +++ b/planetiler-core/src/main/java/com/onthegomap/planetiler/FeatureMerge.java @@ -124,7 +124,7 @@ private static List mergeGeometries( List result = new ArrayList<>(features.size()); var groupedByAttrs = groupByAttrs(features, result, geometryType); for (List groupedFeatures : groupedByAttrs) { - VectorTile.Feature feature1 = groupedFeatures.get(0); + VectorTile.Feature feature1 = groupedFeatures.getFirst(); if (groupedFeatures.size() == 1) { result.add(feature1); } else { @@ -158,7 +158,7 @@ public static List mergeLineStrings(List List result = new ArrayList<>(features.size()); var groupedByAttrs = groupByAttrs(features, result, GeometryType.LINE); for (List groupedFeatures : groupedByAttrs) { - VectorTile.Feature feature1 = groupedFeatures.get(0); + VectorTile.Feature feature1 = groupedFeatures.getFirst(); double lengthLimit = lengthLimitCalculator.apply(feature1.attrs()); // as a shortcut, can skip line merging only if: @@ -300,7 +300,7 @@ public static List mergeNearbyPolygons(List> groupedByAttrs = groupByAttrs(features, result, GeometryType.POLYGON); for (List groupedFeatures : groupedByAttrs) { List outPolygons = new ArrayList<>(); - VectorTile.Feature feature1 = groupedFeatures.get(0); + VectorTile.Feature feature1 = groupedFeatures.getFirst(); List geometries = new ArrayList<>(groupedFeatures.size()); for (var feature : groupedFeatures) { try { @@ -331,7 +331,7 @@ public static List mergeNearbyPolygons(List removePointsOutsideBuffer(List (T feature, int hilbert) {} + private record WithIndex(T feature, int hilbert) {} } diff --git a/planetiler-core/src/main/java/com/onthegomap/planetiler/VectorTile.java b/planetiler-core/src/main/java/com/onthegomap/planetiler/VectorTile.java index 05adad325e..6d15b14fd5 100644 --- a/planetiler-core/src/main/java/com/onthegomap/planetiler/VectorTile.java +++ b/planetiler-core/src/main/java/com/onthegomap/planetiler/VectorTile.java @@ -263,7 +263,7 @@ private static Geometry decodeCommands(GeometryType geomType, int[] commands, in lineStrings.add(gf.createLineString(coordSeq)); } if (lineStrings.size() == 1) { - geometry = lineStrings.get(0); + geometry = lineStrings.getFirst(); } else if (lineStrings.size() > 1) { geometry = gf.createMultiLineString(lineStrings.toArray(new LineString[0])); } @@ -305,12 +305,12 @@ private static Geometry decodeCommands(GeometryType geomType, int[] commands, in } List polygons = new ArrayList<>(); for (List rings : polygonRings) { - LinearRing shell = rings.get(0); + LinearRing shell = rings.getFirst(); LinearRing[] holes = rings.subList(1, rings.size()).toArray(new LinearRing[rings.size() - 1]); polygons.add(gf.createPolygon(shell, holes)); } if (polygons.size() == 1) { - geometry = polygons.get(0); + geometry = polygons.getFirst(); } if (polygons.size() > 1) { geometry = gf.createMultiPolygon(GeometryFactory.toPolygonArray(polygons)); diff --git a/planetiler-core/src/main/java/com/onthegomap/planetiler/collection/ExternalMergeSort.java b/planetiler-core/src/main/java/com/onthegomap/planetiler/collection/ExternalMergeSort.java index c63269e723..11a63af5be 100644 --- a/planetiler-core/src/main/java/com/onthegomap/planetiler/collection/ExternalMergeSort.java +++ b/planetiler-core/src/main/java/com/onthegomap/planetiler/collection/ExternalMergeSort.java @@ -185,7 +185,7 @@ public void sort() { .sinkToConsumer("worker", workers, group -> { try { readSemaphore.acquire(); - var chunk = group.get(0); + var chunk = group.getFirst(); var others = group.stream().skip(1).toList(); var toSort = time(reading, () -> { // merge all chunks into first one, and remove the others diff --git a/planetiler-core/src/main/java/com/onthegomap/planetiler/expression/Expression.java b/planetiler-core/src/main/java/com/onthegomap/planetiler/expression/Expression.java index bd912f3c3c..22fa9eb0ab 100644 --- a/planetiler-core/src/main/java/com/onthegomap/planetiler/expression/Expression.java +++ b/planetiler-core/src/main/java/com/onthegomap/planetiler/expression/Expression.java @@ -229,7 +229,7 @@ public Expression simplifyOnce() { return TRUE; } if (children.size() == 1) { - return children.get(0).simplifyOnce(); + return children.getFirst().simplifyOnce(); } if (children.contains(FALSE)) { return FALSE; @@ -283,7 +283,7 @@ public Expression simplifyOnce() { return FALSE; } if (children.size() == 1) { - return children.get(0).simplifyOnce(); + return children.getFirst().simplifyOnce(); } if (children.contains(TRUE)) { return TRUE; diff --git a/planetiler-core/src/main/java/com/onthegomap/planetiler/expression/MultiExpression.java b/planetiler-core/src/main/java/com/onthegomap/planetiler/expression/MultiExpression.java index 87c53bf403..484c569333 100644 --- a/planetiler-core/src/main/java/com/onthegomap/planetiler/expression/MultiExpression.java +++ b/planetiler-core/src/main/java/com/onthegomap/planetiler/expression/MultiExpression.java @@ -172,7 +172,7 @@ default List getMatches(WithTags input) { */ default O getOrElse(WithTags input, O defaultValue) { List matches = getMatches(input); - return matches.isEmpty() ? defaultValue : matches.get(0); + return matches.isEmpty() ? defaultValue : matches.getFirst(); } /** @@ -180,7 +180,7 @@ default O getOrElse(WithTags input, O defaultValue) { */ default O getOrElse(Map tags, O defaultValue) { List matches = getMatches(WithTags.from(tags)); - return matches.isEmpty() ? defaultValue : matches.get(0); + return matches.isEmpty() ? defaultValue : matches.getFirst(); } /** Returns true if any expression matches that tags from an input element. */ diff --git a/planetiler-core/src/main/java/com/onthegomap/planetiler/geo/GeoUtils.java b/planetiler-core/src/main/java/com/onthegomap/planetiler/geo/GeoUtils.java index 525b790bbf..0809f4de4b 100644 --- a/planetiler-core/src/main/java/com/onthegomap/planetiler/geo/GeoUtils.java +++ b/planetiler-core/src/main/java/com/onthegomap/planetiler/geo/GeoUtils.java @@ -281,15 +281,15 @@ public static Geometry fixPolygon(Geometry geom, double buffer) throws GeometryE } public static Geometry combineLineStrings(List lineStrings) { - return lineStrings.size() == 1 ? lineStrings.get(0) : createMultiLineString(lineStrings); + return lineStrings.size() == 1 ? lineStrings.getFirst() : createMultiLineString(lineStrings); } public static Geometry combinePolygons(List polys) { - return polys.size() == 1 ? polys.get(0) : createMultiPolygon(polys); + return polys.size() == 1 ? polys.getFirst() : createMultiPolygon(polys); } public static Geometry combinePoints(List points) { - return points.size() == 1 ? points.get(0) : createMultiPoint(points); + return points.size() == 1 ? points.getFirst() : createMultiPoint(points); } /** @@ -383,7 +383,7 @@ public static Geometry polygonToLineString(Geometry geom) throws GeometryExcepti if (lineStrings.isEmpty()) { throw new GeometryException("polygon_to_linestring_empty", "No line strings"); } else if (lineStrings.size() == 1) { - return lineStrings.get(0); + return lineStrings.getFirst(); } else { return createMultiLineString(lineStrings); } @@ -530,7 +530,7 @@ public static Geometry combine(Geometry... geometries) { innerGeometries.add(geom); } } - return innerGeometries.size() == 1 ? innerGeometries.get(0) : + return innerGeometries.size() == 1 ? innerGeometries.getFirst() : JTS_FACTORY.createGeometryCollection(innerGeometries.toArray(Geometry[]::new)); } diff --git a/planetiler-core/src/main/java/com/onthegomap/planetiler/geo/PolygonIndex.java b/planetiler-core/src/main/java/com/onthegomap/planetiler/geo/PolygonIndex.java index 848c1d137e..0d06d9039b 100644 --- a/planetiler-core/src/main/java/com/onthegomap/planetiler/geo/PolygonIndex.java +++ b/planetiler-core/src/main/java/com/onthegomap/planetiler/geo/PolygonIndex.java @@ -45,7 +45,7 @@ private void build() { /** Returns the data associated with the first polygon containing {@code point}. */ public T getOnlyContaining(Point point) { List result = getContaining(point); - return result.isEmpty() ? null : result.get(0); + return result.isEmpty() ? null : result.getFirst(); } /** Returns the data associated with all polygons containing {@code point}. */ @@ -77,7 +77,7 @@ public List getContainingOrNearest(Point point) { List items = index.query(point.getEnvelopeInternal()); // optimization: if there's only one then skip checking contains/distance if (items.size() == 1) { - if (items.get(0) instanceof GeomWithData value) { + if (items.getFirst() instanceof GeomWithData value) { @SuppressWarnings("unchecked") T t = (T) value.data; return List.of(t); } @@ -108,7 +108,7 @@ public List getContainingOrNearest(Point point) { /** Returns the data associated with a polygon that contains {@code point} or nearest polygon if none are found. */ public T get(Point point) { List nearests = getContainingOrNearest(point); - return nearests.isEmpty() ? null : nearests.get(0); + return nearests.isEmpty() ? null : nearests.getFirst(); } /** Indexes {@code item} for all polygons contained in {@code geom}. */ diff --git a/planetiler-core/src/main/java/com/onthegomap/planetiler/reader/osm/OsmMultipolygon.java b/planetiler-core/src/main/java/com/onthegomap/planetiler/reader/osm/OsmMultipolygon.java index 4e18f59498..31ca60a356 100644 --- a/planetiler-core/src/main/java/com/onthegomap/planetiler/reader/osm/OsmMultipolygon.java +++ b/planetiler-core/src/main/java/com/onthegomap/planetiler/reader/osm/OsmMultipolygon.java @@ -232,7 +232,7 @@ private static Set groupParentChildShells(List polygons) { if (numPolygons == 0) { return shells; } - shells.add(polygons.get(0)); + shells.add(polygons.getFirst()); if (numPolygons == 1) { return shells; } diff --git a/planetiler-core/src/main/java/com/onthegomap/planetiler/render/GeometryCoordinateSequences.java b/planetiler-core/src/main/java/com/onthegomap/planetiler/render/GeometryCoordinateSequences.java index 261129183f..60b117f8b9 100644 --- a/planetiler-core/src/main/java/com/onthegomap/planetiler/render/GeometryCoordinateSequences.java +++ b/planetiler-core/src/main/java/com/onthegomap/planetiler/render/GeometryCoordinateSequences.java @@ -122,7 +122,7 @@ static Geometry reassembleLineStrings(List> geoms) { static Geometry reassemblePolygons(List> groups) throws GeometryException { int numGeoms = groups.size(); if (numGeoms == 1) { - return reassemblePolygon(groups.get(0)); + return reassemblePolygon(groups.getFirst()); } else { Polygon[] polygons = new Polygon[numGeoms]; for (int i = 0; i < numGeoms; i++) { @@ -135,7 +135,7 @@ static Geometry reassemblePolygons(List> groups) throws /** Returns a {@link Polygon} built from all outer/inner rings in {@code group}, reversing all inner rings. */ private static Polygon reassemblePolygon(List group) throws GeometryException { try { - LinearRing first = GeoUtils.JTS_FACTORY.createLinearRing(group.get(0)); + LinearRing first = GeoUtils.JTS_FACTORY.createLinearRing(group.getFirst()); LinearRing[] rest = new LinearRing[group.size() - 1]; for (int j = 1; j < group.size(); j++) { CoordinateSequence seq = group.get(j); diff --git a/planetiler-core/src/main/java/com/onthegomap/planetiler/render/TiledGeometry.java b/planetiler-core/src/main/java/com/onthegomap/planetiler/render/TiledGeometry.java index d5b9469ae8..03ffbfc994 100644 --- a/planetiler-core/src/main/java/com/onthegomap/planetiler/render/TiledGeometry.java +++ b/planetiler-core/src/main/java/com/onthegomap/planetiler/render/TiledGeometry.java @@ -258,7 +258,7 @@ private void slicePoint(Coordinate coord) { TileCoord tile = TileCoord.ofXYZ(wrappedX, y, z); double tileY = worldY - y; tileContents.computeIfAbsent(tile, t -> List.of(new ArrayList<>())) - .get(0) + .getFirst() .add(GeoUtils.coordinateSequence(tileX * 256, tileY * 256)); } } @@ -384,7 +384,7 @@ private void addShapeToResults(Map> inProgre for (var entry : inProgressShapes.entrySet()) { TileCoord tileID = entry.getKey(); List inSeqs = entry.getValue(); - if (area && inSeqs.get(0).size() < 4) { + if (area && inSeqs.getFirst().size() < 4) { // not enough points in outer polygon, ignore continue; } @@ -573,20 +573,20 @@ record SkippedSegment(Direction side, int lo, int hi, boolean asc) {} } /* A tile is inside a filled region when there is an odd number of vertical edges to the left and right - + for example a simple shape: --------- out | in | out (0/2) | (1/1) | (2/0) --------- - + or a more complex shape --------- --------- out | in | out | in | (0/4) | (1/3) | (2/2) | (3/1) | | --------- | ------------------------- - + So we keep track of this number by xor'ing the left and right fills repeatedly, then and'ing them together at the end. */ diff --git a/planetiler-core/src/main/java/com/onthegomap/planetiler/stats/ProgressLoggers.java b/planetiler-core/src/main/java/com/onthegomap/planetiler/stats/ProgressLoggers.java index 3d7535ce72..44dce911d2 100644 --- a/planetiler-core/src/main/java/com/onthegomap/planetiler/stats/ProgressLoggers.java +++ b/planetiler-core/src/main/java/com/onthegomap/planetiler/stats/ProgressLoggers.java @@ -275,7 +275,7 @@ private void addDeltaLogger(String name, Supplier supplier, DoubleFunc /** Adds the CPU utilization of every thread starting with {@code prefix} since the last log to output. */ public ProgressLoggers addThreadPoolStats(String name, String prefix) { - boolean first = loggers.isEmpty() || !(loggers.get(loggers.size() - 1) instanceof WorkerPipelineLogger); + boolean first = loggers.isEmpty() || !(loggers.getLast() instanceof WorkerPipelineLogger); try { Map lastThreads = ProcessInfo.getThreadStats(); AtomicLong lastTime = new AtomicLong(System.nanoTime()); diff --git a/planetiler-core/src/main/java/com/onthegomap/planetiler/util/AwsOsm.java b/planetiler-core/src/main/java/com/onthegomap/planetiler/util/AwsOsm.java index 823a2dc316..cdd3a818d2 100644 --- a/planetiler-core/src/main/java/com/onthegomap/planetiler/util/AwsOsm.java +++ b/planetiler-core/src/main/java/com/onthegomap/planetiler/util/AwsOsm.java @@ -95,7 +95,7 @@ protected String searchIndexForDownloadUrl(String searchQuery, List } else if (results.size() > 1) { throw new IllegalArgumentException("Found multiple AWS osm download URLs for " + searchQuery + ": " + results); } - return results.get(0); + return results.getFirst(); } } diff --git a/planetiler-core/src/main/java/com/onthegomap/planetiler/util/Geofabrik.java b/planetiler-core/src/main/java/com/onthegomap/planetiler/util/Geofabrik.java index fe7bf2c0b5..07e514ad6c 100644 --- a/planetiler-core/src/main/java/com/onthegomap/planetiler/util/Geofabrik.java +++ b/planetiler-core/src/main/java/com/onthegomap/planetiler/util/Geofabrik.java @@ -106,7 +106,7 @@ private static String getIfOnly(String name, String searchQuery, List d.id).collect( Collectors.joining(", "))); } else if (values.size() == 1) { - return values.get(0).urls.get("pbf"); + return values.getFirst().urls.get("pbf"); } else { return null; } diff --git a/planetiler-core/src/test/java/com/onthegomap/planetiler/PlanetilerTests.java b/planetiler-core/src/test/java/com/onthegomap/planetiler/PlanetilerTests.java index d1964b296f..8cd3303c7c 100644 --- a/planetiler-core/src/test/java/com/onthegomap/planetiler/PlanetilerTests.java +++ b/planetiler-core/src/test/java/com/onthegomap/planetiler/PlanetilerTests.java @@ -827,7 +827,7 @@ void testReorderNestedMultipolygons() throws Exception { var tileContents = results.tiles.get(TileCoord.ofXYZ(0, 0, 0)); assertEquals(1, tileContents.size()); - Geometry geom = tileContents.get(0).geometry().geom(); + Geometry geom = tileContents.getFirst().geometry().geom(); assertTrue(geom instanceof MultiPolygon, geom.toString()); MultiPolygon multiPolygon = (MultiPolygon) geom; assertSameNormalizedFeature(newPolygon( @@ -1884,7 +1884,7 @@ void testIssue546Terschelling() throws Exception { var point = newPoint(tileX, tileY); assertEquals(1, problematicTile.size()); - var geomCompare = problematicTile.get(0).geometry(); + var geomCompare = problematicTile.getFirst().geometry(); geomCompare.validate(); var geom = geomCompare.geom(); diff --git a/planetiler-core/src/test/java/com/onthegomap/planetiler/VectorTileTest.java b/planetiler-core/src/test/java/com/onthegomap/planetiler/VectorTileTest.java index 84a9f8b4a4..9f065ae40e 100644 --- a/planetiler-core/src/test/java/com/onthegomap/planetiler/VectorTileTest.java +++ b/planetiler-core/src/test/java/com/onthegomap/planetiler/VectorTileTest.java @@ -160,7 +160,7 @@ void testAttributeTypes() { List decoded = VectorTile.decode(encoded); assertEquals(1, decoded.size()); - Map decodedAttributes = decoded.get(0).attrs(); + Map decodedAttributes = decoded.getFirst().attrs(); assertEquals("value1", decodedAttributes.get("key1")); assertEquals(123L, decodedAttributes.get("key2")); assertEquals(234.1f, decodedAttributes.get("key3")); @@ -220,7 +220,7 @@ void testMultiPolygon() { var features = VectorTile.decode(encoded); assertEquals(1, features.size()); - MultiPolygon mp2 = (MultiPolygon) decodeSilently(features.get(0).geometry()); + MultiPolygon mp2 = (MultiPolygon) decodeSilently(features.getFirst().geometry()); assertEquals(mp.getNumGeometries(), mp2.getNumGeometries()); } diff --git a/planetiler-core/src/test/java/com/onthegomap/planetiler/reader/ShapefileReaderTest.java b/planetiler-core/src/test/java/com/onthegomap/planetiler/reader/ShapefileReaderTest.java index 1cb2d20937..b534024796 100644 --- a/planetiler-core/src/test/java/com/onthegomap/planetiler/reader/ShapefileReaderTest.java +++ b/planetiler-core/src/test/java/com/onthegomap/planetiler/reader/ShapefileReaderTest.java @@ -94,9 +94,9 @@ void testReadShapefileLeniently(@TempDir Path dir) throws IOException, Transform assertEquals(1, reader.getFeatureCount()); List features = new ArrayList<>(); reader.readFeatures(features::add); - assertEquals(10.5113, features.get(0).latLonGeometry().getCentroid().getX(), 1e-4); - assertEquals(0, features.get(0).latLonGeometry().getCentroid().getY(), 1e-4); - assertEquals(3, features.get(0).getTag("value")); + assertEquals(10.5113, features.getFirst().latLonGeometry().getCentroid().getX(), 1e-4); + assertEquals(0, features.getFirst().latLonGeometry().getCentroid().getY(), 1e-4); + assertEquals(3, features.getFirst().getTag("value")); } } diff --git a/planetiler-custommap/src/main/java/com/onthegomap/planetiler/custommap/Contexts.java b/planetiler-custommap/src/main/java/com/onthegomap/planetiler/custommap/Contexts.java index 57ca78c959..1ad9a4091d 100644 --- a/planetiler-custommap/src/main/java/com/onthegomap/planetiler/custommap/Contexts.java +++ b/planetiler-custommap/src/main/java/com/onthegomap/planetiler/custommap/Contexts.java @@ -410,7 +410,7 @@ public Object apply(String key) { } public String matchKey() { - return matchKeys().isEmpty() ? null : matchKeys().get(0); + return matchKeys().isEmpty() ? null : matchKeys().getFirst(); } public Object matchValue() { diff --git a/planetiler-custommap/src/main/java/com/onthegomap/planetiler/custommap/expression/ConfigExpression.java b/planetiler-custommap/src/main/java/com/onthegomap/planetiler/custommap/expression/ConfigExpression.java index 58bcf47343..a6be26191c 100644 --- a/planetiler-custommap/src/main/java/com/onthegomap/planetiler/custommap/expression/ConfigExpression.java +++ b/planetiler-custommap/src/main/java/com/onthegomap/planetiler/custommap/expression/ConfigExpression.java @@ -164,7 +164,7 @@ public O apply(I i) { public ConfigExpression simplifyOnce() { return switch (children.size()) { case 0 -> constOf(null); - case 1 -> children.get(0); + case 1 -> children.getFirst(); default -> { var result = children.stream() .flatMap(