Initialize Lists holding GeoJson coordinates with size where possible.
See: #4904
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user