Skip to content

Commit 273fca9

Browse files
ivovandongenosana
authored andcommitted
Make GeometryCollection a Geometry as specified in the spec at sections 1.4 and 3.1.8 (#749)
1 parent 560aaf6 commit 273fca9

11 files changed

Lines changed: 47 additions & 31 deletions

File tree

services-geocoding/src/test/java/com/mapbox/api/geocoding/v5/models/CarmenFeatureTest.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static junit.framework.TestCase.assertEquals;
44
import static junit.framework.TestCase.assertTrue;
5+
import static org.hamcrest.Matchers.isA;
56
import static org.hamcrest.Matchers.notNullValue;
67
import static org.hamcrest.Matchers.nullValue;
78
import static org.hamcrest.core.IsEqual.equalTo;
@@ -11,6 +12,7 @@
1112
import com.mapbox.api.geocoding.v5.GeocodingTestUtils;
1213
import com.mapbox.api.geocoding.v5.MapboxGeocoding;
1314
import com.mapbox.core.TestUtils;
15+
import com.mapbox.geojson.CoordinateContainer;
1416
import com.mapbox.geojson.Point;
1517
import org.junit.Test;
1618
import retrofit2.Response;
@@ -81,8 +83,8 @@ public void fromJson_handlesConversionCorrectly() throws Exception {
8183
assertThat(feature.type(), equalTo("Feature"));
8284
assertEquals(5, feature.context().size());
8385
assertThat(feature.geometry().type(), equalTo("Point"));
84-
assertThat(feature.geometry().coordinates().toString(), equalTo("[-77.036543, "
85-
+ "38.897702]"));
86+
assertThat(((CoordinateContainer) feature.geometry()).coordinates().toString(),
87+
equalTo("[-77.036543, 38.897702]"));
8688
assertThat(feature.address(), equalTo("1600"));
8789
assertThat(feature.id(), equalTo("address.3982178573139850"));
8890
assertEquals(1, feature.placeType().size());
@@ -132,8 +134,8 @@ public void ForwardGeocode_withValidChineseResponse() throws Exception {
132134

133135
assertEquals(3, feature.context().size());
134136
assertThat(feature.geometry().type(), equalTo("Point"));
135-
assertThat(feature.geometry().coordinates().toString(), equalTo("[106.820552, "
136-
+ "39.458115]"));
137+
assertThat(((CoordinateContainer) feature.geometry()).coordinates().toString(),
138+
equalTo("[106.820552, 39.458115]"));
137139
assertThat(feature.id(), equalTo("place.10514057239276310"));
138140
assertThat(feature.relevance(), equalTo(0.99));
139141
assertThat(feature.placeName(), equalTo("中国内蒙古乌海市海南区"));
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.mapbox.geojson;
2+
3+
/**
4+
* Each of the s geometries which make up GeoJson implement this interface and consume a varying
5+
* dimension of {@link Point} list. Since this is varying, each geometry object fulfills the
6+
* contract by replacing the generic with a well defined list of Points.
7+
*
8+
* @param <T> a generic allowing varying dimensions for each GeoJson geometry
9+
* @since 3.0.0
10+
*/
11+
public interface CoordinateContainer<T> extends Geometry {
12+
13+
/**
14+
* the coordinates which define the geometry. Typically a list of points but for some geometry
15+
* such as polygon this can be a list of a list of points, thus the return is generic here.
16+
*
17+
* @return the {@link Point}s which make up the coordinates defining the geometry
18+
* @since 3.0.0
19+
*/
20+
T coordinates();
21+
}
Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,10 @@
11
package com.mapbox.geojson;
22

33
/**
4-
* Each of the seven geometries which make up GeoJson implement this interface and consume a varying
5-
* dimension of {@link Point} list. Since this is varying, each geometry object fulfills the
6-
* contract by replacing the generic with a well defined list of Points.
4+
* Each of the six geometries and {@link GeometryCollection} which make up GeoJson implement this interface.
75
*
8-
* @param <T> a generic allowing varying dimensions for each GeoJson geometry
96
* @since 1.0.0
107
*/
11-
public interface Geometry<T> extends GeoJson {
8+
public interface Geometry extends GeoJson {
129

13-
/**
14-
* the coordinates which define the geometry. Typically a list of points but for some geometry
15-
* such as polygon this can be a list of a list of points, thus the return is generic here.
16-
*
17-
* @return the {@link Point}s which make up the coordinates defining the geometry
18-
* @since 1.0.0
19-
*/
20-
T coordinates();
2110
}

services-geojson/src/main/java/com/mapbox/geojson/GeometryCollection.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.support.annotation.NonNull;
44
import android.support.annotation.Nullable;
5+
56
import com.google.auto.value.AutoValue;
67
import com.google.gson.Gson;
78
import com.google.gson.GsonBuilder;
@@ -61,7 +62,7 @@
6162
* @since 1.0.0
6263
*/
6364
@AutoValue
64-
public abstract class GeometryCollection implements GeoJson, Serializable {
65+
public abstract class GeometryCollection implements Geometry, Serializable {
6566

6667
private static final String TYPE = "GeometryCollection";
6768

@@ -72,7 +73,7 @@ public abstract class GeometryCollection implements GeoJson, Serializable {
7273
*
7374
* @param json a formatted valid JSON string defining a GeoJson Geometry Collection
7475
* @return a new instance of this class defined by the values passed inside this static factory
75-
* method
76+
* method
7677
* @since 1.0.0
7778
*/
7879
public static GeometryCollection fromJson(String json) {
@@ -89,7 +90,7 @@ public static GeometryCollection fromJson(String json) {
8990
*
9091
* @param geometries a non-null list of geometry which makes up this collection
9192
* @return a new instance of this class defined by the values passed inside this static factory
92-
* method
93+
* method
9394
* @since 1.0.0
9495
*/
9596
public static GeometryCollection fromGeometries(@NonNull List<Geometry> geometries) {
@@ -101,7 +102,7 @@ public static GeometryCollection fromGeometries(@NonNull List<Geometry> geometri
101102
*
102103
* @param geometry a non-null object of type geometry which makes up this collection
103104
* @return a new instance of this class defined by the values passed inside this static factory
104-
* method
105+
* method
105106
* @since 3.0.0
106107
*/
107108
public static GeometryCollection fromGeometry(@NonNull Geometry geometry) {
@@ -115,7 +116,7 @@ public static GeometryCollection fromGeometry(@NonNull Geometry geometry) {
115116
* @param geometries a non-null list of geometry which makes up this collection
116117
* @param bbox optionally include a bbox definition as a double array
117118
* @return a new instance of this class defined by the values passed inside this static factory
118-
* method
119+
* method
119120
* @since 1.0.0
120121
*/
121122
public static GeometryCollection fromGeometries(@NonNull List<Geometry> geometries,
@@ -129,7 +130,7 @@ public static GeometryCollection fromGeometries(@NonNull List<Geometry> geometri
129130
* @param geometry a non-null object of type geometry which makes up this collection
130131
* @param bbox optionally include a bbox definition as a double array
131132
* @return a new instance of this class defined by the values passed inside this static factory
132-
* method
133+
* method
133134
* @since 3.0.0
134135
*/
135136
public static GeometryCollection fromGeometry(@NonNull Geometry geometry,
@@ -143,7 +144,7 @@ public static GeometryCollection fromGeometry(@NonNull Geometry geometry,
143144
* {@link GeometryCollection}.
144145
*
145146
* @return a String which describes the TYPE of geometry, for this object it will always return
146-
* {@code GeometryCollection}
147+
* {@code GeometryCollection}
147148
* @since 1.0.0
148149
*/
149150
@NonNull

services-geojson/src/main/java/com/mapbox/geojson/LineString.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
* @since 1.0.0
5252
*/
5353
@AutoValue
54-
public abstract class LineString implements Geometry<List<Point>>, Serializable {
54+
public abstract class LineString implements CoordinateContainer<List<Point>>, Serializable {
5555

5656
private static final String TYPE = "LineString";
5757

services-geojson/src/main/java/com/mapbox/geojson/MultiLineString.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
* @since 1.0.0
5252
*/
5353
@AutoValue
54-
public abstract class MultiLineString implements Geometry<List<List<Point>>>, Serializable {
54+
public abstract class MultiLineString implements CoordinateContainer<List<List<Point>>>, Serializable {
5555

5656
private static final String TYPE = "MultiLineString";
5757

services-geojson/src/main/java/com/mapbox/geojson/MultiPoint.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
* @since 1.0.0
3737
*/
3838
@AutoValue
39-
public abstract class MultiPoint implements Geometry<List<Point>>, Serializable {
39+
public abstract class MultiPoint implements CoordinateContainer<List<Point>>, Serializable {
4040

4141
private static final String TYPE = "MultiPoint";
4242

services-geojson/src/main/java/com/mapbox/geojson/MultiPolygon.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
* @since 1.0.0
7070
*/
7171
@AutoValue
72-
public abstract class MultiPolygon implements Geometry<List<List<List<Point>>>>, Serializable {
72+
public abstract class MultiPolygon implements CoordinateContainer<List<List<List<Point>>>>, Serializable {
7373

7474
private static final String TYPE = "MultiPolygon";
7575

services-geojson/src/main/java/com/mapbox/geojson/Point.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
* @since 1.0.0
5959
*/
6060
@AutoValue
61-
public abstract class Point implements Geometry<List<Double>>, Serializable {
61+
public abstract class Point implements CoordinateContainer<List<Double>>, Serializable {
6262

6363
private static final String TYPE = "Point";
6464

services-geojson/src/main/java/com/mapbox/geojson/Polygon.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
* @since 1.0.0
6060
*/
6161
@AutoValue
62-
public abstract class Polygon implements Geometry<List<List<Point>>>, Serializable {
62+
public abstract class Polygon implements CoordinateContainer<List<List<Point>>>, Serializable {
6363

6464
private static final String TYPE = "Polygon";
6565

0 commit comments

Comments
 (0)