mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-07 19:42:17 +00:00
Adjusted classes for use of Position. Minor Test-Changes
This commit is contained in:
1 parent
d7108af177
commit
90755dd8af
5 files changed
+39
-14
No files matched your search
@@ -2,6 +2,7 @@ package com.sap.sailing.geocoding;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
import com.sap.sailing.domain.common.Distance;
|
||||
import com.sap.sailing.domain.common.Position;
|
||||
|
||||
public interface Placemark {
|
||||
@@ -11,8 +12,9 @@ public interface Placemark {
|
||||
Position getPosition();
|
||||
String getType();
|
||||
long getPopulation();
|
||||
|
||||
float distanceFrom(double latDeg, double lngDeg);
|
||||
|
||||
Distance distanceFrom(Position p);
|
||||
Distance distanceFrom(double latDeg, double lngDeg);
|
||||
String getCountryName();
|
||||
|
||||
/**
|
||||
@@ -23,7 +25,8 @@ public interface Placemark {
|
||||
public class ByPopulation implements Comparator<Placemark> {
|
||||
@Override
|
||||
public int compare(Placemark p1, Placemark p2) {
|
||||
return new Long(p1.getPopulation()).compareTo(p2.getPopulation());
|
||||
return p1.getPopulation() > p2.getPopulation() ? 1 : p1.getPopulation() < p2.getPopulation() ? -1 : 0;
|
||||
// return new Long(p1.getPopulation()).compareTo(p2.getPopulation());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,15 +6,19 @@ import java.util.List;
|
||||
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
import com.sap.sailing.domain.common.Position;
|
||||
import com.sap.sailing.geocoding.impl.ReverseGeocoderImpl;
|
||||
|
||||
public interface ReverseGeocoder {
|
||||
final ReverseGeocoder INSTANCE = new ReverseGeocoderImpl();
|
||||
final String GEONAMES_USER = "sailtracking";
|
||||
|
||||
|
||||
Placemark getPlacemark(double latDeg, double lngDeg) throws IOException, ParseException;
|
||||
Placemark getPlacemark(Position p) throws IOException, ParseException;
|
||||
|
||||
List<Placemark> getPlacemarkNear(double latDeg, double lngDeg, float radius) throws IOException, ParseException;
|
||||
|
||||
List<Placemark> getPlacemarkNear(Position p, float radius) throws IOException, ParseException;
|
||||
|
||||
Placemark getPlacemarkBest(double latDeg, double lngDeg, float radius, Comparator<Placemark> comp) throws IOException, ParseException;
|
||||
Placemark getPlacemarkBest(Position p, float radius, Comparator<Placemark> comp) throws IOException, ParseException;
|
||||
}
|
||||
+10
-5
@@ -1,5 +1,7 @@
|
||||
package com.sap.sailing.geocoding.impl;
|
||||
|
||||
import com.sap.sailing.domain.common.DegreePosition;
|
||||
import com.sap.sailing.domain.common.Distance;
|
||||
import com.sap.sailing.domain.common.Position;
|
||||
import com.sap.sailing.geocoding.Placemark;
|
||||
|
||||
@@ -43,10 +45,15 @@ public class PlacemarkImpl implements Placemark {
|
||||
return population;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public float distanceFrom(double latDeg, double lngDeg) {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
public Distance distanceFrom(Position p) {
|
||||
return position.getDistance(p);
|
||||
}
|
||||
@Override
|
||||
public Distance distanceFrom(double latDeg, double lngDeg) {
|
||||
Position p = new DegreePosition(latDeg, lngDeg);
|
||||
return distanceFrom(p);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -100,7 +107,5 @@ public class PlacemarkImpl implements Placemark {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
+13
@@ -45,6 +45,10 @@ public class ReverseGeocoderImpl implements ReverseGeocoder {
|
||||
|
||||
return p;
|
||||
}
|
||||
@Override
|
||||
public Placemark getPlacemark(Position p) throws IOException, ParseException {
|
||||
return getPlacemark(p.getLatDeg(), p.getLngDeg());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Placemark> getPlacemarkNear(double latDeg, double lngDeg, float radius) throws IOException, ParseException {
|
||||
@@ -71,6 +75,10 @@ public class ReverseGeocoderImpl implements ReverseGeocoder {
|
||||
|
||||
return placemarks;
|
||||
}
|
||||
@Override
|
||||
public List<Placemark> getPlacemarkNear(Position p, float radius) throws IOException, ParseException {
|
||||
return getPlacemarkNear(p.getLatDeg(), p.getLngDeg(), radius);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Placemark getPlacemarkBest(double latDeg, double lngDeg, float radius, Comparator<Placemark> comp) throws IOException, ParseException {
|
||||
@@ -79,6 +87,11 @@ public class ReverseGeocoderImpl implements ReverseGeocoder {
|
||||
|
||||
return placemarks.get(placemarks.size() - 1);
|
||||
}
|
||||
@Override
|
||||
public Placemark getPlacemarkBest(Position p, float radius, Comparator<Placemark> comp) throws IOException,
|
||||
ParseException {
|
||||
return getPlacemarkBest(p.getLatDeg(), p.getLngDeg(), radius, comp);
|
||||
}
|
||||
|
||||
private Placemark JSONToPlacemark(JSONObject json) {
|
||||
String name = (String) json.get("toponymName");
|
||||
|
||||
Reference in new issue
Block a user