Skip to content

Commit 38f183c

Browse files
Cameron Macezugaldia
authored andcommitted
[Not Ready] started work on geojson docs (#20)
1 parent 4170f93 commit 38f183c

14 files changed

Lines changed: 328 additions & 145 deletions

libjava/lib/src/main/java/com/mapbox/services/commons/geojson/Feature.java

Lines changed: 55 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
import com.mapbox.services.commons.models.Position;
99

1010
/**
11-
* Created by antonio on 1/30/16.
11+
* A GeoJSON object with the type "Feature" is a feature object.
12+
*
13+
* @see <a href='geojson.org/geojson-spec.html#feature-objects'>Official GeoJSON Feature Specifications</a>
1214
*/
1315
public class Feature implements GeoJSON {
1416

@@ -17,69 +19,108 @@ public class Feature implements GeoJSON {
1719
private final JsonObject properties;
1820
private final String id;
1921

20-
/*
21-
* Private constructor
22+
/**
23+
* Private constructor.
24+
*
25+
* @param geometry {@link Geometry} object.
26+
* @param properties of this feature as JSON.
27+
* @param id common identifier of this feature.
2228
*/
23-
2429
private Feature(Geometry geometry, JsonObject properties, String id) {
2530
this.geometry = geometry;
2631
this.properties = properties;
2732
this.id = id;
2833
}
2934

30-
/*
31-
* Getters
35+
/**
36+
* Should always be "Feature".
37+
*
38+
* @return String "Feature".
3239
*/
33-
3440
@Override
3541
public String getType() {
3642
return type;
3743
}
3844

45+
/**
46+
* Get the features {@link Geometry}.
47+
*
48+
* @return {@link Geometry} of the feature or null if not set.
49+
*/
3950
public Geometry getGeometry() {
4051
return geometry;
4152
}
4253

54+
/**
55+
* Returns the optional properties of this feature as JSON.
56+
*
57+
* @return the properties of this feature
58+
*/
4359
public JsonObject getProperties() {
4460
return properties;
4561
}
4662

63+
/**
64+
* The optional, common identifier of this feature.
65+
*
66+
* @return The common identifier of this feature, if set.
67+
*/
4768
public String getId() {
4869
return id;
4970
}
5071

51-
/*
52-
* Factories
72+
/**
73+
* Create a feature from geometry.
74+
*
75+
* @param geometry {@link Geometry} object.
5376
*/
54-
5577
public static Feature fromGeometry(Geometry geometry) {
5678
return new Feature(geometry, null, null);
5779
}
5880

81+
/**
82+
* Create a feature from geometry.
83+
*
84+
* @param geometry {@link Geometry} object.
85+
* @param properties of this feature as JSON.
86+
*/
5987
public static Feature fromGeometry(Geometry geometry, JsonObject properties) {
6088
return new Feature(geometry, properties, null);
6189
}
6290

91+
/**
92+
* Create a feature from geometry.
93+
*
94+
* @param geometry {@link Geometry} object.
95+
* @param properties of this feature as JSON.
96+
* @param id common identifier of this feature.
97+
*/
6398
public static Feature fromGeometry(Geometry geometry, JsonObject properties, String id) {
6499
return new Feature(geometry, properties, id);
65100
}
66101

67-
/*
68-
* Gson interface
102+
/**
103+
* Create a GeoJSON feature object from JSON.
104+
*
105+
* @param json String of JSON making up a feature.
106+
* @return {@link Feature} GeoJSON object.
69107
*/
70-
71108
public static Feature fromJson(String json) {
72109
GsonBuilder gson = new GsonBuilder();
73110
gson.registerTypeAdapter(Position.class, new PositionDeserializer());
74111
gson.registerTypeAdapter(Geometry.class, new GeometryDeserializer());
75112
return gson.create().fromJson(json, Feature.class);
76113
}
77114

115+
/**
116+
* Convert feature into JSON.
117+
*
118+
* @return String containing feature JSON.
119+
*/
78120
@Override
79121
public String toJson() {
80122
GsonBuilder gson = new GsonBuilder();
81123
gson.registerTypeAdapter(Position.class, new PositionSerializer());
82124
return gson.create().toJson(this);
83125
}
84-
85126
}

libjava/lib/src/main/java/com/mapbox/services/commons/geojson/FeatureCollection.java

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,58 +9,76 @@
99
import java.util.List;
1010

1111
/**
12-
* Created by antonio on 1/30/16.
12+
* A GeoJSON object with the type "FeatureCollection" is a feature object which represents a
13+
* collection of feature objects.
14+
*
15+
* @see <a href='geojson.org/geojson-spec.html#feature-collection-objects'>Official GeoJSON FeatureCollection Specifications</a>
1316
*/
1417
public class FeatureCollection implements GeoJSON {
1518

1619
private final String type = "FeatureCollection";
1720
private final List<com.mapbox.services.commons.geojson.Feature> features;
1821

19-
/*
20-
* Private constructor
22+
/**
23+
* Private constructor.
24+
*
25+
* @param features List of {@link Feature}.
2126
*/
22-
2327
private FeatureCollection(List<com.mapbox.services.commons.geojson.Feature> features) {
2428
this.features = features;
2529
}
2630

27-
/*
28-
* Getters
31+
/**
32+
* Should always be "FeatureCollection".
33+
*
34+
* @return String "FeatureCollection".
2935
*/
30-
3136
@Override
3237
public String getType() {
3338
return type;
3439
}
3540

41+
/**
42+
* Get the List containing all the features within collection.
43+
*
44+
* @return List of features within collection.
45+
*/
3646
public List<com.mapbox.services.commons.geojson.Feature> getFeatures() {
3747
return features;
3848
}
3949

40-
/*
41-
* Factories
50+
/**
51+
* Create a {@link FeatureCollection} from a List of features.
52+
*
53+
* @param features List of {@link Feature}
54+
* @return new {@link FeatureCollection}
4255
*/
43-
4456
public static FeatureCollection fromFeatures(List<com.mapbox.services.commons.geojson.Feature> features) {
4557
return new FeatureCollection(features);
4658
}
4759

48-
/*
49-
* Gson interface
60+
/**
61+
* Create a GeoJSON feature collection object from JSON.
62+
*
63+
* @param json String of JSON making up a feature collection.
64+
* @return {@link FeatureCollection} GeoJSON object.
5065
*/
51-
5266
public static FeatureCollection fromJson(String json) {
5367
GsonBuilder gson = new GsonBuilder();
5468
gson.registerTypeAdapter(Position.class, new PositionDeserializer());
5569
gson.registerTypeAdapter(Geometry.class, new GeometryDeserializer());
5670
return gson.create().fromJson(json, FeatureCollection.class);
5771
}
5872

73+
/**
74+
* Convert feature collection into JSON.
75+
*
76+
* @return String containing feature collection JSON.
77+
*/
5978
@Override
6079
public String toJson() {
6180
GsonBuilder gson = new GsonBuilder();
6281
gson.registerTypeAdapter(Position.class, new PositionSerializer());
6382
return gson.create().toJson(this);
6483
}
65-
6684
}

libjava/lib/src/main/java/com/mapbox/services/commons/geojson/GeoJSON.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.mapbox.services.commons.geojson;
22

33
/**
4-
* Created by antonio on 1/30/16.
4+
* Interface implemented by all GeoJSON objects, contains common fields.
55
*/
66
public interface GeoJSON {
77

libjava/lib/src/main/java/com/mapbox/services/commons/geojson/Geometry.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package com.mapbox.services.commons.geojson;
22

33
/**
4-
* Created by antonio on 1/30/16.
4+
* Interface implemented by all Geometry objects, contains common fields.
5+
* @param <T> the type of the coordinates, normally a list interface of positions.
56
*/
67
public interface Geometry<T> extends com.mapbox.services.commons.geojson.GeoJSON {
78

libjava/lib/src/main/java/com/mapbox/services/commons/geojson/GeometryCollection.java

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,58 +9,76 @@
99
import java.util.List;
1010

1111
/**
12-
* Created by antonio on 1/30/16.
12+
* A GeoJSON object with the type "GeometryCollection" is a geometry object which represents a
13+
* collection of geometry objects.
14+
*
15+
* @see <a href='geojson.org/geojson-spec.html#geometry-collection'>Official GeoJSON GeometryCollection Specifications</a>
1316
*/
14-
public class GeometryCollection implements com.mapbox.services.commons.geojson.GeoJSON {
17+
public class GeometryCollection implements GeoJSON {
1518

1619
private final String type = "GeometryCollection";
1720
private final List<com.mapbox.services.commons.geojson.Geometry> geometries;
1821

19-
/*
20-
* Private constructor
22+
/**
23+
* Private constructor.
24+
*
25+
* @param geometries List of {@link Geometry}.
2126
*/
22-
2327
public GeometryCollection(List<com.mapbox.services.commons.geojson.Geometry> geometries) {
2428
this.geometries = geometries;
2529
}
2630

27-
/*
28-
* Getters
31+
/**
32+
* Should always be "GeometryCollection".
33+
*
34+
* @return String "GeometryCollection".
2935
*/
30-
3136
@Override
3237
public String getType() {
3338
return type;
3439
}
3540

41+
/**
42+
* Get the List containing all the geometries within collection.
43+
*
44+
* @return List of geometries within collection.
45+
*/
3646
public List<com.mapbox.services.commons.geojson.Geometry> getGeometries() {
3747
return geometries;
3848
}
3949

40-
/*
41-
* Factories
50+
/**
51+
* Create a {@link GeometryCollection} from a List of geometries.
52+
*
53+
* @param geometries List of {@link Geometry}
54+
* @return new {@link GeometryCollection}
4255
*/
43-
4456
public static GeometryCollection fromGeometries(List<com.mapbox.services.commons.geojson.Geometry> geometries) {
4557
return new GeometryCollection(geometries);
4658
}
4759

48-
/*
49-
* Gson interface
60+
/**
61+
* Create a GeoJSON geometry collection object from JSON.
62+
*
63+
* @param json String of JSON making up a geometry collection.
64+
* @return {@link GeometryCollection} GeoJSON object.
5065
*/
51-
5266
public static GeometryCollection fromJson(String json) {
5367
GsonBuilder gson = new GsonBuilder();
5468
gson.registerTypeAdapter(Position.class, new PositionDeserializer());
5569
gson.registerTypeAdapter(Geometry.class, new GeometryDeserializer());
5670
return gson.create().fromJson(json, GeometryCollection.class);
5771
}
5872

73+
/**
74+
* Convert geometry collection into JSON.
75+
*
76+
* @return String containing geometry collection JSON.
77+
*/
5978
@Override
6079
public String toJson() {
6180
GsonBuilder gson = new GsonBuilder();
6281
gson.registerTypeAdapter(Position.class, new PositionSerializer());
6382
return gson.create().toJson(this);
6483
}
65-
6684
}

0 commit comments

Comments
 (0)