sequenced collections

use-21-features
Mike Barry 2023-10-26 21:06:33 -04:00
rodzic 9ac7ed4b84
commit 507ea4e7b4
19 zmienionych plików z 42 dodań i 42 usunięć

Wyświetl plik

@ -47,7 +47,7 @@ public class BenchmarkMbtilesRead {
List<TileCoord> 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();

Wyświetl plik

@ -124,7 +124,7 @@ public class FeatureMerge {
List<VectorTile.Feature> result = new ArrayList<>(features.size());
var groupedByAttrs = groupByAttrs(features, result, geometryType);
for (List<VectorTile.Feature> 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 class FeatureMerge {
List<VectorTile.Feature> result = new ArrayList<>(features.size());
var groupedByAttrs = groupByAttrs(features, result, GeometryType.LINE);
for (List<VectorTile.Feature> 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 class FeatureMerge {
Collection<List<VectorTile.Feature>> groupedByAttrs = groupByAttrs(features, result, GeometryType.POLYGON);
for (List<VectorTile.Feature> groupedFeatures : groupedByAttrs) {
List<Polygon> outPolygons = new ArrayList<>();
VectorTile.Feature feature1 = groupedFeatures.get(0);
VectorTile.Feature feature1 = groupedFeatures.getFirst();
List<Geometry> geometries = new ArrayList<>(groupedFeatures.size());
for (var feature : groupedFeatures) {
try {
@ -331,7 +331,7 @@ public class FeatureMerge {
}
merged = GeoUtils.snapAndFixPolygon(merged, stats, "merge").reverse();
} else {
merged = polygonGroup.get(0);
merged = polygonGroup.getFirst();
if (!(merged instanceof Polygonal) || merged.getEnvelopeInternal().getArea() < minArea) {
continue;
}
@ -572,5 +572,5 @@ public class FeatureMerge {
return result;
}
private record WithIndex<T> (T feature, int hilbert) {}
private record WithIndex<T>(T feature, int hilbert) {}
}

Wyświetl plik

@ -263,7 +263,7 @@ public class VectorTile {
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 @@ public class VectorTile {
}
List<Polygon> polygons = new ArrayList<>();
for (List<LinearRing> 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));

Wyświetl plik

@ -185,7 +185,7 @@ class ExternalMergeSort implements FeatureSort {
.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

Wyświetl plik

@ -229,7 +229,7 @@ public interface Expression extends Simplifiable<Expression> {
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 interface Expression extends Simplifiable<Expression> {
return FALSE;
}
if (children.size() == 1) {
return children.get(0).simplifyOnce();
return children.getFirst().simplifyOnce();
}
if (children.contains(TRUE)) {
return TRUE;

Wyświetl plik

@ -172,7 +172,7 @@ public record MultiExpression<T> (List<Entry<T>> expressions) implements Simplif
*/
default O getOrElse(WithTags input, O defaultValue) {
List<O> matches = getMatches(input);
return matches.isEmpty() ? defaultValue : matches.get(0);
return matches.isEmpty() ? defaultValue : matches.getFirst();
}
/**
@ -180,7 +180,7 @@ public record MultiExpression<T> (List<Entry<T>> expressions) implements Simplif
*/
default O getOrElse(Map<String, Object> tags, O defaultValue) {
List<O> 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. */

Wyświetl plik

@ -281,15 +281,15 @@ public class GeoUtils {
}
public static Geometry combineLineStrings(List<LineString> lineStrings) {
return lineStrings.size() == 1 ? lineStrings.get(0) : createMultiLineString(lineStrings);
return lineStrings.size() == 1 ? lineStrings.getFirst() : createMultiLineString(lineStrings);
}
public static Geometry combinePolygons(List<Polygon> polys) {
return polys.size() == 1 ? polys.get(0) : createMultiPolygon(polys);
return polys.size() == 1 ? polys.getFirst() : createMultiPolygon(polys);
}
public static Geometry combinePoints(List<Point> points) {
return points.size() == 1 ? points.get(0) : createMultiPoint(points);
return points.size() == 1 ? points.getFirst() : createMultiPoint(points);
}
/**
@ -383,7 +383,7 @@ public class GeoUtils {
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 class GeoUtils {
innerGeometries.add(geom);
}
}
return innerGeometries.size() == 1 ? innerGeometries.get(0) :
return innerGeometries.size() == 1 ? innerGeometries.getFirst() :
JTS_FACTORY.createGeometryCollection(innerGeometries.toArray(Geometry[]::new));
}

Wyświetl plik

@ -45,7 +45,7 @@ public class PolygonIndex<T> {
/** Returns the data associated with the first polygon containing {@code point}. */
public T getOnlyContaining(Point point) {
List<T> 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 class PolygonIndex<T> {
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 class PolygonIndex<T> {
/** Returns the data associated with a polygon that contains {@code point} or nearest polygon if none are found. */
public T get(Point point) {
List<T> 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}. */

Wyświetl plik

@ -232,7 +232,7 @@ public class OsmMultipolygon {
if (numPolygons == 0) {
return shells;
}
shells.add(polygons.get(0));
shells.add(polygons.getFirst());
if (numPolygons == 1) {
return shells;
}

Wyświetl plik

@ -122,7 +122,7 @@ class GeometryCoordinateSequences {
static Geometry reassemblePolygons(List<List<CoordinateSequence>> 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 @@ class GeometryCoordinateSequences {
/** Returns a {@link Polygon} built from all outer/inner rings in {@code group}, reversing all inner rings. */
private static Polygon reassemblePolygon(List<CoordinateSequence> 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);

Wyświetl plik

@ -258,7 +258,7 @@ public class TiledGeometry {
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 @@ public class TiledGeometry {
for (var entry : inProgressShapes.entrySet()) {
TileCoord tileID = entry.getKey();
List<CoordinateSequence> 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 @@ public class TiledGeometry {
}
/*
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.
*/

Wyświetl plik

@ -275,7 +275,7 @@ public class ProgressLoggers {
/** 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<Long, ProcessInfo.ThreadState> lastThreads = ProcessInfo.getThreadStats();
AtomicLong lastTime = new AtomicLong(System.nanoTime());

Wyświetl plik

@ -95,7 +95,7 @@ public class AwsOsm {
} else if (results.size() > 1) {
throw new IllegalArgumentException("Found multiple AWS osm download URLs for " + searchQuery + ": " + results);
}
return results.get(0);
return results.getFirst();
}
}

Wyświetl plik

@ -106,7 +106,7 @@ public class Geofabrik {
"Multiple " + name + " for '" + searchQuery + "': " + values.stream().map(d -> 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;
}

Wyświetl plik

@ -827,7 +827,7 @@ class PlanetilerTests {
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 @@ class PlanetilerTests {
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();

Wyświetl plik

@ -160,7 +160,7 @@ class VectorTileTest {
List<VectorTile.Feature> decoded = VectorTile.decode(encoded);
assertEquals(1, decoded.size());
Map<String, Object> decodedAttributes = decoded.get(0).attrs();
Map<String, Object> decodedAttributes = decoded.getFirst().attrs();
assertEquals("value1", decodedAttributes.get("key1"));
assertEquals(123L, decodedAttributes.get("key2"));
assertEquals(234.1f, decodedAttributes.get("key3"));
@ -220,7 +220,7 @@ class VectorTileTest {
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());
}

Wyświetl plik

@ -94,9 +94,9 @@ class ShapefileReaderTest {
assertEquals(1, reader.getFeatureCount());
List<SimpleFeature> 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"));
}
}

Wyświetl plik

@ -410,7 +410,7 @@ public class Contexts {
}
public String matchKey() {
return matchKeys().isEmpty() ? null : matchKeys().get(0);
return matchKeys().isEmpty() ? null : matchKeys().getFirst();
}
public Object matchValue() {

Wyświetl plik

@ -164,7 +164,7 @@ public interface ConfigExpression<I extends ScriptContext, O>
public ConfigExpression<I, O> simplifyOnce() {
return switch (children.size()) {
case 0 -> constOf(null);
case 1 -> children.get(0);
case 1 -> children.getFirst();
default -> {
var result = children.stream()
.flatMap(