mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-20 04:35:32 +00:00
Placemark serialization bug solved
This commit is contained in:
+1
-1
@@ -50,7 +50,7 @@ public abstract class AbstractBearing implements Bearing {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return (int) (1023 ^ Double.doubleToLongBits(getDegrees()));
|
||||
return 1023 ^ (int) getDegrees();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+34
-37
@@ -20,36 +20,36 @@ public interface Placemark extends Serializable {
|
||||
* @return The 2 letters country code of the Placemark
|
||||
*/
|
||||
String getCountryCode();
|
||||
//
|
||||
// /**
|
||||
// * @return The {@link Position} of the Placemark
|
||||
// */
|
||||
// Position getPosition();
|
||||
|
||||
/**
|
||||
* @return The {@link Position} of the Placemark
|
||||
*/
|
||||
Position getPosition();
|
||||
|
||||
/**
|
||||
* @return The population of the Placemark
|
||||
*/
|
||||
long getPopulation();
|
||||
//
|
||||
// /**
|
||||
// * @param position The {@link Position} from which the distance is calculated
|
||||
// * @return The {@link Distance} between the given {@link Position} and the Placemark
|
||||
// */
|
||||
// Distance distanceFrom(Position position);
|
||||
//
|
||||
// /**
|
||||
// * Creates a new {@link Position} out of the given coordinates and calculates the distance between {@link Position} and
|
||||
// * the Placemark via {@link Placemark#distanceFrom(Position) distanceFrom(Position)}.
|
||||
// * @param latDeg Latitude in degrees
|
||||
// * @param lngDeg Longitude in degrees
|
||||
// * @return The {@link Distance} between the given coordinates and the Placemark
|
||||
// */
|
||||
// Distance distanceFrom(double latDeg, double lngDeg);
|
||||
//
|
||||
// /**
|
||||
// * @return The name of the country where the Placemark is located
|
||||
// */
|
||||
// String getCountryName();
|
||||
|
||||
/**
|
||||
* @param position The {@link Position} from which the distance is calculated
|
||||
* @return The {@link Distance} between the given {@link Position} and the Placemark
|
||||
*/
|
||||
Distance distanceFrom(Position position);
|
||||
|
||||
/**
|
||||
* Creates a new {@link Position} out of the given coordinates and calculates the distance between {@link Position} and
|
||||
* the Placemark via {@link Placemark#distanceFrom(Position) distanceFrom(Position)}.
|
||||
* @param latDeg Latitude in degrees
|
||||
* @param lngDeg Longitude in degrees
|
||||
* @return The {@link Distance} between the given coordinates and the Placemark
|
||||
*/
|
||||
Distance distanceFrom(double latDeg, double lngDeg);
|
||||
|
||||
/**
|
||||
* @return The name of the country where the Placemark is located
|
||||
*/
|
||||
String getCountryName();
|
||||
|
||||
|
||||
|
||||
@@ -64,8 +64,7 @@ public interface Placemark extends Serializable {
|
||||
public class ByPopulation implements Comparator<Placemark> {
|
||||
@Override
|
||||
public int compare(Placemark p1, Placemark p2) {
|
||||
// return p1.getPopulation() > p2.getPopulation() ? 1 : p1.getPopulation() < p2.getPopulation() ? -1 : 0;
|
||||
return 0;
|
||||
return p1.getPopulation() > p2.getPopulation() ? 1 : p1.getPopulation() < p2.getPopulation() ? -1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,11 +87,10 @@ public interface Placemark extends Serializable {
|
||||
|
||||
@Override
|
||||
public int compare(Placemark p1, Placemark p2) {
|
||||
// Distance d1 = p1.distanceFrom(position);
|
||||
// Distance d2 = p2.distanceFrom(position);
|
||||
//
|
||||
// return d1.compareTo(d2);
|
||||
return 0;
|
||||
Distance d1 = p1.distanceFrom(position);
|
||||
Distance d2 = p2.distanceFrom(position);
|
||||
|
||||
return d1.compareTo(d2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,11 +104,10 @@ public interface Placemark extends Serializable {
|
||||
|
||||
@Override
|
||||
public int compare(Placemark p1, Placemark p2) {
|
||||
// double r1 = p1.getPopulation() / p1.distanceFrom(position).getKilometers();
|
||||
// double r2 = p2.getPopulation() / p2.distanceFrom(position).getKilometers();
|
||||
//
|
||||
// return r1 > r2 ? 1 : r1 < r2 ? -1 : 0;
|
||||
return 0;
|
||||
double r1 = p1.getPopulation() / p1.distanceFrom(position).getKilometers();
|
||||
double r2 = p2.getPopulation() / p2.distanceFrom(position).getKilometers();
|
||||
|
||||
return r1 > r2 ? 1 : r1 < r2 ? -1 : 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -39,7 +39,7 @@ public abstract class AbstractSpeedImpl implements Speed {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return (int) (31 * Double.doubleToLongBits(getMetersPerSecond()));
|
||||
return 31 * (int) getMetersPerSecond();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+24
-26
@@ -1,7 +1,5 @@
|
||||
package com.sap.sailing.domain.common.impl;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.sap.sailing.domain.common.CountryCodeFactory;
|
||||
import com.sap.sailing.domain.common.Distance;
|
||||
import com.sap.sailing.domain.common.Placemark;
|
||||
@@ -27,19 +25,19 @@ public class PlacemarkImpl implements Placemark {
|
||||
/**
|
||||
* Creates a new Placemark with the given parameters as attributes.
|
||||
*/
|
||||
public PlacemarkImpl(String name, String countryCode/*, SerializablePosition position*/, long population) {
|
||||
public PlacemarkImpl(String name, String countryCode, SerializablePosition position, long population) {
|
||||
this.name = name;
|
||||
this.countryCode = countryCode;
|
||||
// this.position = position;
|
||||
this.position = position;
|
||||
this.population = population;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Creates a new Placemark with the given parameters as attributes and a <code>population</code> of <code>0</code>;
|
||||
// */
|
||||
// public PlacemarkImpl(String name, String countryCode, String countryName, SerializablePosition position, String type) {
|
||||
// this(name, countryCode, position, 0);
|
||||
// }
|
||||
/**
|
||||
* Creates a new Placemark with the given parameters as attributes and a <code>population</code> of <code>0</code>;
|
||||
*/
|
||||
public PlacemarkImpl(String name, String countryCode, String countryName, SerializablePosition position, String type) {
|
||||
this(name, countryCode, position, 0);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
@@ -56,22 +54,22 @@ public class PlacemarkImpl implements Placemark {
|
||||
public long getPopulation() {
|
||||
return population;
|
||||
}
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// public Distance distanceFrom(Position position) {
|
||||
// return this.position.getPosition().getDistance(position);
|
||||
// }
|
||||
// @Override
|
||||
// public Distance distanceFrom(double latDeg, double lngDeg) {
|
||||
// Position p = new DegreePosition(latDeg, lngDeg);
|
||||
// return distanceFrom(p);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String getCountryName() {
|
||||
// return CountryCodeFactory.INSTANCE.getFromTwoLetterISOName(countryCode).getName();
|
||||
// }
|
||||
|
||||
|
||||
@Override
|
||||
public Distance distanceFrom(Position position) {
|
||||
return this.position.getPosition().getDistance(position);
|
||||
}
|
||||
@Override
|
||||
public Distance distanceFrom(double latDeg, double lngDeg) {
|
||||
Position p = new DegreePosition(latDeg, lngDeg);
|
||||
return distanceFrom(p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCountryName() {
|
||||
return CountryCodeFactory.INSTANCE.getFromTwoLetterISOName(countryCode).getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
+1
-2
@@ -18,8 +18,7 @@ public class SerializablePositionImpl implements SerializablePosition {
|
||||
|
||||
@Override
|
||||
public Position getPosition() {
|
||||
// return new DegreePosition(latDeg, lngDeg);
|
||||
return null;
|
||||
return new DegreePosition(latDeg, lngDeg);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+56
-56
@@ -965,62 +965,62 @@ public abstract class TrackedRaceImpl implements TrackedRace, CourseListener {
|
||||
Placemark startBest = null;
|
||||
Placemark finishBest = null;
|
||||
|
||||
// //Get start postition
|
||||
// Waypoint start = getRace().getCourse().getFirstWaypoint();
|
||||
// Iterable<MarkPassing> startPassings = getMarkPassingsInOrder(start);
|
||||
// MarkPassing startPassing = startPassings.iterator().next();
|
||||
// Position startPosition = getApproximatePosition(start, startPassing.getTimePoint());
|
||||
//
|
||||
// try {
|
||||
// //Get distance to nearest placemark and calculate the search radius
|
||||
// Placemark startNearest = ReverseGeocoder.INSTANCE.getPlacemarkNearest(startPosition);
|
||||
// Distance startNearestDistance = startNearest.distanceFrom(startPosition);
|
||||
// double startRadius = startNearestDistance.getKilometers() * GEONAMES_RADIUS_CACLCULATION_FACTOR;
|
||||
//
|
||||
// //Get the estimated best start place
|
||||
// startBest = ReverseGeocoder.INSTANCE.getPlacemarkLast(startPosition, startRadius,
|
||||
// new Placemark.ByPopulationDistanceRatio(startPosition));
|
||||
// } catch (IOException e) {
|
||||
// logger.throwing(TrackedRaceImpl.class.getName(), "getPlaceOrder()", e);
|
||||
// } catch (ParseException e) {
|
||||
// logger.throwing(TrackedRaceImpl.class.getName(), "getPlaceOrder()", e);
|
||||
// }
|
||||
//
|
||||
// //Get finish position
|
||||
// Waypoint finish = getRace().getCourse().getLastWaypoint();
|
||||
// Iterable<MarkPassing> finishPassings = getMarkPassingsInOrder(finish);
|
||||
// Iterator<MarkPassing> finishPassingsIterator = finishPassings.iterator();
|
||||
// MarkPassing finishPassing = null;
|
||||
// while (finishPassingsIterator.hasNext()) {
|
||||
// finishPassing = (MarkPassing) finishPassingsIterator.next();
|
||||
// }
|
||||
// Position finishPosition = getApproximatePosition(finish, finishPassing.getTimePoint());
|
||||
//
|
||||
// if (startPosition.getDistance(finishPosition).getKilometers() > ReverseGeocoder.POSITION_CACHE_DISTANCE_LIMIT_IN_KM) {
|
||||
// try {
|
||||
// // Get distance to nearest placemark and calculate the search radius
|
||||
// Placemark finishNearest = ReverseGeocoder.INSTANCE.getPlacemarkNearest(finishPosition);
|
||||
// Distance finishNearestDistance = finishNearest.distanceFrom(finishPosition);
|
||||
// double finishRadius = finishNearestDistance.getKilometers() * GEONAMES_RADIUS_CACLCULATION_FACTOR;
|
||||
//
|
||||
// // Get the estimated best finish place
|
||||
// finishBest = ReverseGeocoder.INSTANCE.getPlacemarkLast(finishPosition, finishRadius,
|
||||
// new Placemark.ByPopulationDistanceRatio(finishPosition));
|
||||
// } catch (IOException e) {
|
||||
// logger.throwing(TrackedRaceImpl.class.getName(), "getPlaceOrder()", e);
|
||||
// } catch (ParseException e) {
|
||||
// logger.throwing(TrackedRaceImpl.class.getName(), "getPlaceOrder()", e);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (startBest != null) {
|
||||
// final List<Placemark> places = new ArrayList<Placemark>();
|
||||
// places.add(startBest);
|
||||
// if (!startBest.equals(finishBest)) {
|
||||
// places.add(finishBest);
|
||||
// }
|
||||
// order = new RacePlaceOrderImpl(places);
|
||||
// }
|
||||
//Get start postition
|
||||
Waypoint start = getRace().getCourse().getFirstWaypoint();
|
||||
Iterable<MarkPassing> startPassings = getMarkPassingsInOrder(start);
|
||||
MarkPassing startPassing = startPassings.iterator().next();
|
||||
Position startPosition = getApproximatePosition(start, startPassing.getTimePoint());
|
||||
|
||||
try {
|
||||
//Get distance to nearest placemark and calculate the search radius
|
||||
Placemark startNearest = ReverseGeocoder.INSTANCE.getPlacemarkNearest(startPosition);
|
||||
Distance startNearestDistance = startNearest.distanceFrom(startPosition);
|
||||
double startRadius = startNearestDistance.getKilometers() * GEONAMES_RADIUS_CACLCULATION_FACTOR;
|
||||
|
||||
//Get the estimated best start place
|
||||
startBest = ReverseGeocoder.INSTANCE.getPlacemarkLast(startPosition, startRadius,
|
||||
new Placemark.ByPopulationDistanceRatio(startPosition));
|
||||
} catch (IOException e) {
|
||||
logger.throwing(TrackedRaceImpl.class.getName(), "getPlaceOrder()", e);
|
||||
} catch (ParseException e) {
|
||||
logger.throwing(TrackedRaceImpl.class.getName(), "getPlaceOrder()", e);
|
||||
}
|
||||
|
||||
//Get finish position
|
||||
Waypoint finish = getRace().getCourse().getLastWaypoint();
|
||||
Iterable<MarkPassing> finishPassings = getMarkPassingsInOrder(finish);
|
||||
Iterator<MarkPassing> finishPassingsIterator = finishPassings.iterator();
|
||||
MarkPassing finishPassing = null;
|
||||
while (finishPassingsIterator.hasNext()) {
|
||||
finishPassing = (MarkPassing) finishPassingsIterator.next();
|
||||
}
|
||||
Position finishPosition = getApproximatePosition(finish, finishPassing.getTimePoint());
|
||||
|
||||
if (startPosition.getDistance(finishPosition).getKilometers() > ReverseGeocoder.POSITION_CACHE_DISTANCE_LIMIT_IN_KM) {
|
||||
try {
|
||||
// Get distance to nearest placemark and calculate the search radius
|
||||
Placemark finishNearest = ReverseGeocoder.INSTANCE.getPlacemarkNearest(finishPosition);
|
||||
Distance finishNearestDistance = finishNearest.distanceFrom(finishPosition);
|
||||
double finishRadius = finishNearestDistance.getKilometers() * GEONAMES_RADIUS_CACLCULATION_FACTOR;
|
||||
|
||||
// Get the estimated best finish place
|
||||
finishBest = ReverseGeocoder.INSTANCE.getPlacemarkLast(finishPosition, finishRadius,
|
||||
new Placemark.ByPopulationDistanceRatio(finishPosition));
|
||||
} catch (IOException e) {
|
||||
logger.throwing(TrackedRaceImpl.class.getName(), "getPlaceOrder()", e);
|
||||
} catch (ParseException e) {
|
||||
logger.throwing(TrackedRaceImpl.class.getName(), "getPlaceOrder()", e);
|
||||
}
|
||||
}
|
||||
|
||||
if (startBest != null) {
|
||||
final List<Placemark> places = new ArrayList<Placemark>();
|
||||
places.add(startBest);
|
||||
if (!startBest.equals(finishBest)) {
|
||||
places.add(finishBest);
|
||||
}
|
||||
order = new RacePlaceOrderImpl(places);
|
||||
}
|
||||
|
||||
return order;
|
||||
}
|
||||
|
||||
+3
-3
@@ -11,9 +11,9 @@ public class PlacemarkTest {
|
||||
|
||||
@Test
|
||||
public void placemarkEqualsTest() {
|
||||
// Placemark p1 = new PlacemarkImpl("Kiel", "DE", "Germany", new SerializablePositionImpl(55, 10), "P");
|
||||
// Placemark p2 = new PlacemarkImpl("Kiel", "DE", "Germany", new SerializablePositionImpl(55, 10), "P");
|
||||
// Assert.assertEquals(p1, p2);
|
||||
Placemark p1 = new PlacemarkImpl("Kiel", "DE", "Germany", new SerializablePositionImpl(55, 10), "P");
|
||||
Placemark p2 = new PlacemarkImpl("Kiel", "DE", "Germany", new SerializablePositionImpl(55, 10), "P");
|
||||
Assert.assertEquals(p1, p2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+45
-45
@@ -18,66 +18,66 @@ import com.sap.sailing.geocoding.ReverseGeocoder;
|
||||
public class ReverseGeocoderTest {
|
||||
|
||||
private ReverseGeocoder geocoder = ReverseGeocoder.INSTANCE;
|
||||
// private static final Placemark KIEL = new PlacemarkImpl("Kiel", "DE", new SerializablePositionImpl(54.32132926107913, 10.1348876953125), 232758);
|
||||
private static final Placemark KIEL = new PlacemarkImpl("Kiel", "DE", new SerializablePositionImpl(54.32132926107913, 10.1348876953125), 232758);
|
||||
private static final Position KIEL_POSITION = new DegreePosition(54.3231063453431, 10.12265682220459);
|
||||
|
||||
@Test
|
||||
public void getPlacemarkSimpleTest() {
|
||||
// //Simple Test in Kiel center to check the connection and the parsing from JSONObject to Placemark
|
||||
// try {
|
||||
// Placemark kielReversed = geocoder.getPlacemarkNearest(KIEL_POSITION);
|
||||
// Assert.assertEquals(KIEL, kielReversed);
|
||||
// } catch (IOException e) {
|
||||
// Assert.fail(e.getMessage());
|
||||
// } catch (ParseException e) {
|
||||
// Assert.fail(e.getMessage());
|
||||
// }
|
||||
//Simple Test in Kiel center to check the connection and the parsing from JSONObject to Placemark
|
||||
try {
|
||||
Placemark kielReversed = geocoder.getPlacemarkNearest(KIEL_POSITION);
|
||||
Assert.assertEquals(KIEL, kielReversed);
|
||||
} catch (IOException e) {
|
||||
Assert.fail(e.getMessage());
|
||||
} catch (ParseException e) {
|
||||
Assert.fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPlacemarkNearSimpleTest() {
|
||||
// try {
|
||||
// List<Placemark> placemarks = geocoder.getPlacemarksNear(KIEL_POSITION, 20);
|
||||
// Assert.assertFalse(placemarks.isEmpty());
|
||||
// } catch (IOException e) {
|
||||
// Assert.fail(e.getMessage());
|
||||
// } catch (ParseException e) {
|
||||
// Assert.fail(e.getMessage());
|
||||
// }
|
||||
try {
|
||||
List<Placemark> placemarks = geocoder.getPlacemarksNear(KIEL_POSITION, 20);
|
||||
Assert.assertFalse(placemarks.isEmpty());
|
||||
} catch (IOException e) {
|
||||
Assert.fail(e.getMessage());
|
||||
} catch (ParseException e) {
|
||||
Assert.fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPlacemarkBestTest() {
|
||||
// Position abroad = new DegreePosition(54.43334, 10.299999);
|
||||
// Placemark firstByDistance = new PlacemarkImpl("Wendtorf", "DE", new SerializablePositionImpl(54.4166667, 10.3), 1139);
|
||||
//
|
||||
// try {
|
||||
// Placemark p = geocoder.getPlacemarkLast(abroad, 20, new Placemark.ByPopulation());
|
||||
// Assert.assertEquals(KIEL, p);
|
||||
//
|
||||
// p = geocoder.getPlacemarkFirst(abroad, 20, new Placemark.ByDistance(abroad));
|
||||
// Assert.assertEquals(firstByDistance, p);
|
||||
//
|
||||
// p = geocoder.getPlacemarkLast(abroad, 20, new Placemark.ByPopulationDistanceRatio(abroad));
|
||||
// Assert.assertEquals(KIEL, p);
|
||||
// } catch (IOException e) {
|
||||
// Assert.fail(e.getMessage());
|
||||
// } catch (ParseException e) {
|
||||
// Assert.fail(e.getMessage());
|
||||
// }
|
||||
Position abroad = new DegreePosition(54.43334, 10.299999);
|
||||
Placemark firstByDistance = new PlacemarkImpl("Wendtorf", "DE", new SerializablePositionImpl(54.4166667, 10.3), 1139);
|
||||
|
||||
try {
|
||||
Placemark p = geocoder.getPlacemarkLast(abroad, 20, new Placemark.ByPopulation());
|
||||
Assert.assertEquals(KIEL, p);
|
||||
|
||||
p = geocoder.getPlacemarkFirst(abroad, 20, new Placemark.ByDistance(abroad));
|
||||
Assert.assertEquals(firstByDistance, p);
|
||||
|
||||
p = geocoder.getPlacemarkLast(abroad, 20, new Placemark.ByPopulationDistanceRatio(abroad));
|
||||
Assert.assertEquals(KIEL, p);
|
||||
} catch (IOException e) {
|
||||
Assert.fail(e.getMessage());
|
||||
} catch (ParseException e) {
|
||||
Assert.fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPlacemarkNearWithOffshorePosition() {
|
||||
// Position offshore = new DegreePosition(75.16330024622059, -0.087890625);
|
||||
// long radius = 300;
|
||||
// try {
|
||||
// List<Placemark> placemarks = geocoder.getPlacemarksNear(offshore, radius);
|
||||
// Assert.assertNull(placemarks);
|
||||
// } catch (IOException e) {
|
||||
// Assert.fail(e.getMessage());
|
||||
// } catch (ParseException e) {
|
||||
// Assert.fail(e.getMessage());
|
||||
// }
|
||||
Position offshore = new DegreePosition(75.16330024622059, -0.087890625);
|
||||
long radius = 300;
|
||||
try {
|
||||
List<Placemark> placemarks = geocoder.getPlacemarksNear(offshore, radius);
|
||||
Assert.assertNull(placemarks);
|
||||
} catch (IOException e) {
|
||||
Assert.fail(e.getMessage());
|
||||
} catch (ParseException e) {
|
||||
Assert.fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -167,12 +167,12 @@ public class ReverseGeocoderImpl implements ReverseGeocoder {
|
||||
} catch (ClassCastException e) {
|
||||
lngDeg = ((Long) json.get("lng")).doubleValue();
|
||||
}
|
||||
// SerializablePosition position = new SerializablePositionImpl(latDeg, lngDeg);
|
||||
SerializablePosition position = new SerializablePositionImpl(latDeg, lngDeg);
|
||||
|
||||
long population = (Long) json.get("population");
|
||||
|
||||
if (name != null && lngDeg != null && latDeg != null) {
|
||||
return new PlacemarkImpl(name, countryCode/*, position*/, population);
|
||||
return new PlacemarkImpl(name, countryCode, position, population);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user