opendatalab-de / geojson-jackson

GeoJson POJOs for Jackson - serialize and deserialize objects with ease
http://blog.opendatalab.de
Apache License 2.0
264 stars 94 forks source link

add Visitor for GeoJsonObject #10

Closed twillouer closed 9 years ago

grundid commented 9 years ago

Thank you for your pull request and sorry for getting to you so late.

I have one question regarding the implementation: as far as I can see is the implementation of the accept method the same in all classes. why do you define the method as abstract in the GeoJsonObject then? If you put in the implementation there we can save a lot of redundant code.

twillouer commented 9 years ago

Hi,

good question :)

In the Visitor interface:

+public interface GeoJsonObjectVisitor<T> {
+ T visit(GeometryCollection geoJsonObject);
+ T visit(FeatureCollection geoJsonObject);
+ T visit(Point geoJsonObject);
+ T visit(Feature geoJsonObject);
+ T visit(MultiLineString geoJsonObject);
+ T visit(Polygon geoJsonObject);
+ T visit(MultiPolygon geoJsonObject);
+ T visit(MultiPoint geoJsonObject);
+ T visit(LineString geoJsonObject);
+}

you see all possible visit methods, dependenting of concrete classes.

In each concrete class, you have the method "accept" who call "visit(this)". Java can resolve in compile time the right call (like visit(LineString) in LineString, etc)