avoid null points in additions to competitor charts

This commit is contained in:
Axel Uhl
2012-03-02 16:50:09 +01:00
parent 61a026ff0a
commit 7e1fdd6aaf
3 changed files with 12 additions and 11 deletions
@@ -1141,12 +1141,14 @@ public abstract class TrackedRaceImpl implements TrackedRace, CourseListener {
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;
if (startNearest != null) {
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));
// 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) {
@@ -53,7 +53,7 @@ public class ReverseGeocoderImpl implements ReverseGeocoder {
p = cachedPlacemarks.getC().get(0);
} else {
JSONArray geonames = callNearestService(position);
if (!geonames.isEmpty()) {
if (geonames != null && !geonames.isEmpty()) {
p = JSONToPlacemark((JSONObject) geonames.get(0));
if (p != null) {
@@ -300,17 +300,16 @@ implements CompetitorSelectionChangeListener, RaceSelectionChangeListener, TimeL
Date dateOfNewestSeriesPoint = compSeriesPoints.length == 0 ? new Date(0) : new Date(
compSeriesPoints[compSeriesPoints.length - 1].getX().longValue());
List<Pair<Date, Double>> raceData = competitorData.getRaceDataAfterDate(dateOfNewestSeriesPoint);
Point[] points = new Point[raceData.size()];
int i=0;
List<Point> points = new ArrayList<Point>();
for (Pair<Date, Double> data : raceData) {
if (data.getA() != null && data.getB() != null) {
Point competitorPoint = new Point(data.getA().getTime(), data.getB());
points[i++] = competitorPoint;
points.add(competitorPoint);
}
}
Point[] newPoints = new Point[compSeriesPoints.length + points.length];
Point[] newPoints = new Point[compSeriesPoints.length + points.size()];
System.arraycopy(compSeriesPoints, 0, newPoints, 0, compSeriesPoints.length);
System.arraycopy(points, 0, newPoints, compSeriesPoints.length, points.length);
System.arraycopy(points.toArray(), 0, newPoints, compSeriesPoints.length, points.size());
compSeries.setPoints(newPoints);
//Adding the series if chart doesn't contain it