Browse Source

Initialize Lists holding GeoJson coordinates with size where possible.

See: #4904
issue/4969
Christoph Strobl 7 months ago
parent
commit
d7ff6b1b66
No known key found for this signature in database
GPG Key ID: E6054036D0C37A4B
  1. 4
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/geo/GeoJsonGeometryCollection.java
  2. 5
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/geo/GeoJsonMultiLineString.java
  3. 3
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/geo/GeoJsonMultiPoint.java
  4. 4
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/geo/GeoJsonMultiPolygon.java
  5. 4
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/geo/GeoJsonPolygon.java

4
spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/geo/GeoJsonGeometryCollection.java

@ -34,7 +34,7 @@ public class GeoJsonGeometryCollection implements GeoJson<Iterable<GeoJson<?>>>
private static final String TYPE = "GeometryCollection"; 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. * 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"); Assert.notNull(geometries, "Geometries must not be null");
this.geometries.addAll(geometries); this.geometries = new ArrayList<>(geometries);
} }
@Override @Override

5
spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/geo/GeoJsonMultiLineString.java

@ -35,7 +35,7 @@ public class GeoJsonMultiLineString implements GeoJson<Iterable<GeoJsonLineStrin
private static final String TYPE = "MultiLineString"; 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. * 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"); Assert.notEmpty(lines, "Points for MultiLineString must not be null");
this.coordinates = new ArrayList<>(lines.length);
for (List<Point> line : lines) { for (List<Point> line : lines) {
this.coordinates.add(new GeoJsonLineString(line)); 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"); Assert.notNull(lines, "Lines for MultiLineString must not be null");
this.coordinates.addAll(lines); this.coordinates = new ArrayList<>(lines);
} }
@Override @Override

3
spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/geo/GeoJsonMultiPoint.java

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

4
spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/geo/GeoJsonMultiPolygon.java

@ -33,7 +33,7 @@ public class GeoJsonMultiPolygon implements GeoJson<Iterable<GeoJsonPolygon>> {
private static final String TYPE = "MultiPolygon"; 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. * 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"); Assert.notNull(polygons, "Polygons for MultiPolygon must not be null");
this.coordinates.addAll(polygons); this.coordinates = new ArrayList<>(polygons);
} }
@Override @Override

4
spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/geo/GeoJsonPolygon.java

@ -42,7 +42,7 @@ public class GeoJsonPolygon extends Polygon implements GeoJson<List<GeoJsonLineS
private static final long serialVersionUID = 3936163018187247185L; private static final long serialVersionUID = 3936163018187247185L;
private static final String TYPE = "Polygon"; 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. * 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) { public GeoJsonPolygon(List<Point> points) {
super(points); super(points);
this.coordinates = new ArrayList<>(1);
this.coordinates.add(new GeoJsonLineString(points)); this.coordinates.add(new GeoJsonLineString(points));
} }

Loading…
Cancel
Save