Skip to content

Commit 8b43af2

Browse files
authored
optimize capacity & add assert messages in GeoJson.
Original Pull Request #3064 Closes #3063 Signed-off-by: 정보교 (Bogus Jung) <[email protected]>
1 parent 64f88ae commit 8b43af2

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

Diff for: src/main/java/org/springframework/data/elasticsearch/core/geo/GeoJson.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
/**
2323
* Interface definition for structures defined in <a href="https://geojson.org">GeoJSON</a>
24-
* format. copied from Spring Data Mongodb
24+
* format. copied from Spring Data Mongodb
2525
*
2626
* @author Christoph Strobl
2727
* @since 1.7

Diff for: src/main/java/org/springframework/data/elasticsearch/core/geo/GeoJsonLineString.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public static GeoJsonLineString of(Point first, Point second, Point... others) {
6969
Assert.notNull(second, "Second point must not be null!");
7070
Assert.notNull(others, "Additional points must not be null!");
7171

72-
List<Point> points = new ArrayList<>();
72+
List<Point> points = new ArrayList<>(2 + others.length);
7373
points.add(first);
7474
points.add(second);
7575
points.addAll(Arrays.asList(others));
@@ -103,7 +103,7 @@ public static GeoJsonLineString of(GeoPoint first, GeoPoint second, GeoPoint...
103103
Assert.notNull(second, "Second point must not be null!");
104104
Assert.notNull(others, "Additional points must not be null!");
105105

106-
List<Point> points = new ArrayList<>();
106+
List<Point> points = new ArrayList<>(2 + others.length);
107107
points.add(GeoPoint.toPoint(first));
108108
points.add(GeoPoint.toPoint(second));
109109
points.addAll(Arrays.stream(others).map(GeoPoint::toPoint).collect(Collectors.toList()));

Diff for: src/main/java/org/springframework/data/elasticsearch/core/geo/GeoJsonMultiPoint.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public static GeoJsonMultiPoint of(Point first, Point second, Point... others) {
6969
Assert.notNull(second, "Second point must not be null!");
7070
Assert.notNull(others, "Additional points must not be null!");
7171

72-
List<Point> points = new ArrayList<>();
72+
List<Point> points = new ArrayList<>(2 + others.length);
7373
points.add(first);
7474
points.add(second);
7575
points.addAll(Arrays.asList(others));
@@ -103,7 +103,7 @@ public static GeoJsonMultiPoint of(GeoPoint first, GeoPoint second, GeoPoint...
103103
Assert.notNull(second, "Second point must not be null!");
104104
Assert.notNull(others, "Additional points must not be null!");
105105

106-
List<Point> points = new ArrayList<>();
106+
List<Point> points = new ArrayList<>(2 + others.length);
107107
points.add(GeoPoint.toPoint(first));
108108
points.add(GeoPoint.toPoint(second));
109109
points.addAll(Arrays.stream(others).map(GeoPoint::toPoint).collect(Collectors.toList()));

Diff for: src/main/java/org/springframework/data/elasticsearch/core/geo/GeoJsonPolygon.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,13 @@ public List<GeoJsonLineString> getCoordinates() {
189189
@SafeVarargs
190190
private static <T> List<T> asList(T first, T second, T third, T fourth, T... others) {
191191

192-
ArrayList<T> result = new ArrayList<>(3 + others.length);
192+
Assert.notNull(first, "First element must not be null!");
193+
Assert.notNull(second, "Second element must not be null!");
194+
Assert.notNull(third, "Third element must not be null!");
195+
Assert.notNull(fourth, "Fourth element must not be null!");
196+
Assert.notNull(others, "Additional elements must not be null!");
197+
198+
ArrayList<T> result = new ArrayList<>(4 + others.length);
193199

194200
result.add(first);
195201
result.add(second);

0 commit comments

Comments
 (0)