-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #406 from dickschoeller/370-codebeat-geocoderesult…
…builder Fixes #370 - codebeat issues in GeocodeResultBuilder
- Loading branch information
Showing
7 changed files
with
225 additions
and
130 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
...persistence/src/main/java/org/schoellerfamily/geoservice/model/builder/BoundsBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.schoellerfamily.geoservice.model.builder; | ||
|
||
import java.util.List; | ||
|
||
import org.geojson.Feature; | ||
import org.geojson.LngLatAlt; | ||
import org.geojson.Polygon; | ||
|
||
import com.google.maps.model.Bounds; | ||
|
||
/** | ||
* @author Dick Schoeller | ||
*/ | ||
public interface BoundsBuilder extends LatLngBuilder { | ||
/** | ||
* Create a Bounds from a GeoServiceBounds. | ||
* | ||
* @param feature the bounding box feature | ||
* @return the Bounds | ||
*/ | ||
default Bounds toBounds(final Feature feature) { | ||
if (feature == null) { | ||
return null; | ||
} | ||
final Polygon polygon = (Polygon) feature.getGeometry(); | ||
final List<List<LngLatAlt>> coordinates = polygon.getCoordinates(); | ||
if (coordinates == null || coordinates.isEmpty()) { | ||
return new Bounds(); | ||
} | ||
final List<LngLatAlt> list = coordinates.get(0); | ||
final Bounds bounds = toBounds(list.get(2), list.get(0)); | ||
return bounds; | ||
} | ||
|
||
/** | ||
* Create Bounds from corners. | ||
* | ||
* @param northeast the northeast corner | ||
* @param southwest the southwest corner | ||
* @return the Bounds | ||
*/ | ||
default Bounds toBounds(final LngLatAlt northeast, | ||
final LngLatAlt southwest) { | ||
final Bounds bounds = new Bounds(); | ||
bounds.northeast = toLatLng(northeast); | ||
bounds.southwest = toLatLng(southwest); | ||
return bounds; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...ce-persistence/src/main/java/org/schoellerfamily/geoservice/model/builder/BoxBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.schoellerfamily.geoservice.model.builder; | ||
|
||
import org.geojson.Feature; | ||
import org.schoellerfamily.geoservice.model.GeoServiceBounds; | ||
|
||
import com.google.maps.model.Bounds; | ||
|
||
/** | ||
* @author Dick Schoeller | ||
*/ | ||
public interface BoxBuilder extends LngLatAltBuilder { | ||
/** | ||
* Create a Feature containing a single Polygon describing the bounding box | ||
* from the provided Bounds. | ||
* | ||
* @param id the ID string | ||
* @param bounds the Bounds | ||
* @return the Feature | ||
*/ | ||
default Feature toBox(final String id, final Bounds bounds) { | ||
if (bounds == null) { | ||
return null; | ||
} | ||
if (bounds.southwest == null || bounds.northeast == null) { | ||
throw new IllegalArgumentException( | ||
"Must have legitimate bounding box"); | ||
} | ||
return GeoServiceBounds.createBounds(id, | ||
toLngLatAlt(bounds.southwest), | ||
toLngLatAlt(bounds.northeast)); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...ersistence/src/main/java/org/schoellerfamily/geoservice/model/builder/FeatureBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.schoellerfamily.geoservice.model.builder; | ||
|
||
import org.geojson.Feature; | ||
import org.geojson.Point; | ||
|
||
import com.google.maps.model.LatLng; | ||
import com.google.maps.model.LocationType; | ||
|
||
/** | ||
* @author Dick Schoeller | ||
*/ | ||
public interface FeatureBuilder { | ||
/** | ||
* Create a GeoJSON Point from a LatLng. | ||
* | ||
* @param latLng the LatLng | ||
* @param locationType the location type | ||
* @return the GeoServiceLatLng | ||
*/ | ||
default Feature toLocationFeature(final LatLng latLng, | ||
final LocationType locationType) { | ||
if (latLng == null) { | ||
final Feature feature = new Feature(); | ||
feature.setProperty("locationType", locationType); | ||
feature.setId("location"); | ||
return feature; | ||
} | ||
final Point point = new Point(latLng.lng, latLng.lat); | ||
final Feature feature = new Feature(); | ||
feature.setGeometry(point); | ||
feature.setProperty("locationType", locationType); | ||
feature.setId("location"); | ||
return feature; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...persistence/src/main/java/org/schoellerfamily/geoservice/model/builder/LatLngBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.schoellerfamily.geoservice.model.builder; | ||
|
||
import org.geojson.LngLatAlt; | ||
import org.geojson.Point; | ||
|
||
import com.google.maps.model.LatLng; | ||
|
||
/** | ||
* @author Dick Schoeller | ||
*/ | ||
public interface LatLngBuilder { | ||
/** | ||
* Create a LatLng from a GeoJSON LngLatAlt. | ||
* | ||
* @param lla the LngLatAlt | ||
* @return the LatLng | ||
*/ | ||
default LatLng toLatLng(final LngLatAlt lla) { | ||
if (lla == null) { | ||
return null; | ||
} | ||
return new LatLng(lla.getLatitude(), lla.getLongitude()); | ||
} | ||
|
||
/** | ||
* Create a LatLng from a GeoJSON Point. | ||
* | ||
* @param point the Point | ||
* @return the LatLng | ||
*/ | ||
default LatLng toLatLng(final Point point) { | ||
if (point == null) { | ||
return null; | ||
} | ||
return toLatLng(point.getCoordinates()); | ||
} | ||
} |
Oops, something went wrong.