Initialize Lists holding GeoJson coordinates with size where possible.

See: #4904
This commit is contained in:
Christoph Strobl
2025-05-28 10:13:29 +02:00
parent 532dd289ed
commit d7ff6b1b66
5 changed files with 11 additions and 9 deletions

View File

@@ -34,7 +34,7 @@ public class GeoJsonGeometryCollection implements GeoJson<Iterable<GeoJson<?>>>
private static final String TYPE = "GeometryCollection";
private final List<GeoJson<?>> geometries = new ArrayList<GeoJson<?>>();
private final List<GeoJson<?>> geometries;
/**
* Creates a new {@link GeoJsonGeometryCollection} for the given {@link GeoJson} instances.
@@ -45,7 +45,7 @@ public class GeoJsonGeometryCollection implements GeoJson<Iterable<GeoJson<?>>>
Assert.notNull(geometries, "Geometries must not be null");
this.geometries.addAll(geometries);
this.geometries = new ArrayList<>(geometries);
}
@Override

View File

@@ -35,7 +35,7 @@ public class GeoJsonMultiLineString implements GeoJson<Iterable<GeoJsonLineStrin
private static final String TYPE = "MultiLineString";
private List<GeoJsonLineString> coordinates = new ArrayList<GeoJsonLineString>();
private final List<GeoJsonLineString> coordinates;
/**
* Creates new {@link GeoJsonMultiLineString} for the given {@link Point}s.
@@ -46,6 +46,7 @@ public class GeoJsonMultiLineString implements GeoJson<Iterable<GeoJsonLineStrin
Assert.notEmpty(lines, "Points for MultiLineString must not be null");
this.coordinates = new ArrayList<>(lines.length);
for (List<Point> line : lines) {
this.coordinates.add(new GeoJsonLineString(line));
}
@@ -60,7 +61,7 @@ public class GeoJsonMultiLineString implements GeoJson<Iterable<GeoJsonLineStrin
Assert.notNull(lines, "Lines for MultiLineString must not be null");
this.coordinates.addAll(lines);
this.coordinates = new ArrayList<>(lines);
}
@Override

View File

@@ -49,8 +49,7 @@ public class GeoJsonMultiPoint implements GeoJson<Iterable<Point>> {
Assert.notNull(point, "Point must not be null");
this.points = new ArrayList<>();
this.points.add(point);
this.points = List.of(point);
}
/**

View File

@@ -33,7 +33,7 @@ public class GeoJsonMultiPolygon implements GeoJson<Iterable<GeoJsonPolygon>> {
private static final String TYPE = "MultiPolygon";
private List<GeoJsonPolygon> coordinates = new ArrayList<GeoJsonPolygon>();
private final List<GeoJsonPolygon> coordinates;
/**
* Creates a new {@link GeoJsonMultiPolygon} for the given {@link GeoJsonPolygon}s.
@@ -44,7 +44,7 @@ public class GeoJsonMultiPolygon implements GeoJson<Iterable<GeoJsonPolygon>> {
Assert.notNull(polygons, "Polygons for MultiPolygon must not be null");
this.coordinates.addAll(polygons);
this.coordinates = new ArrayList<>(polygons);
}
@Override

View File

@@ -42,7 +42,7 @@ public class GeoJsonPolygon extends Polygon implements GeoJson<List<GeoJsonLineS
private static final long serialVersionUID = 3936163018187247185L;
private static final String TYPE = "Polygon";
private List<GeoJsonLineString> coordinates = new ArrayList<GeoJsonLineString>();
private final List<GeoJsonLineString> coordinates;
/**
* Creates new {@link GeoJsonPolygon} from the given {@link Point}s.
@@ -65,6 +65,8 @@ public class GeoJsonPolygon extends Polygon implements GeoJson<List<GeoJsonLineS
public GeoJsonPolygon(List<Point> points) {
super(points);
this.coordinates = new ArrayList<>(1);
this.coordinates.add(new GeoJsonLineString(points));
}