Ticket #16995: josm_refactor_WayPoint.java_deduplicate-multiple-storage-of-wpt-time.patch
File josm_refactor_WayPoint.java_deduplicate-multiple-storage-of-wpt-time.patch, 34.3 KB (added by , 5 years ago) |
---|
-
src/org/openstreetmap/josm/data/gpx/GpxData.java
8 8 import java.util.Collection; 9 9 import java.util.Collections; 10 10 import java.util.Date; 11 import java.util.DoubleSummaryStatistics;12 11 import java.util.HashMap; 13 12 import java.util.HashSet; 14 13 import java.util.Iterator; 15 14 import java.util.List; 15 import java.util.LongSummaryStatistics; 16 16 import java.util.Map; 17 17 import java.util.NoSuchElementException; 18 18 import java.util.Set; … … 174 174 WayPoint prevLastOwnWp = null; 175 175 Date prevWpTime = null; 176 176 for (WayPoint wp : wpsOld) { 177 Date wpTime = wp. setTimeFromAttribute();177 Date wpTime = wp.getDate(); 178 178 boolean overlap = false; 179 179 if (wpTime != null) { 180 180 for (GpxTrackSegmentSpan ownspan : getSegmentSpans()) { … … 266 266 private final WayPoint lastWp; 267 267 268 268 GpxTrackSegmentSpan(WayPoint a, WayPoint b) { 269 Date at = a.get Time();270 Date bt = b.get Time();269 Date at = a.getDate(); 270 Date bt = b.getDate(); 271 271 inv = bt.before(at); 272 272 if (inv) { 273 273 firstWp = b; … … 323 323 private static WayPoint getNextWpWithTime(GpxTrackSegment seg, boolean forward) { 324 324 List<WayPoint> wps = new ArrayList<>(seg.getWayPoints()); 325 325 for (int i = forward ? 0 : wps.size() - 1; i >= 0 && i < wps.size(); i += forward ? 1 : -1) { 326 if (wps.get(i). setTimeFromAttribute() != null) {326 if (wps.get(i).hasDate()) { 327 327 return wps.get(i); 328 328 } 329 329 } … … 690 690 * @return minimum and maximum dates in array of 2 elements 691 691 */ 692 692 public static Date[] getMinMaxTimeForTrack(GpxTrack trk) { 693 final DoubleSummaryStatistics statistics = trk.getSegments().stream()693 final LongSummaryStatistics statistics = trk.getSegments().stream() 694 694 .flatMap(seg -> seg.getWayPoints().stream()) 695 .mapTo Double(pnt -> pnt.time)695 .mapToLong(pnt -> pnt.getTimeInMillis()) 696 696 .summaryStatistics(); 697 697 return statistics.getCount() == 0 698 698 ? null 699 : new Date[]{new Date( (long) (statistics.getMin() * 1000)), new Date((long) (statistics.getMax() * 1000))};699 : new Date[]{new Date(statistics.getMin()), new Date(statistics.getMax())}; 700 700 } 701 701 702 702 /** … … 707 707 * @return minimum and maximum dates in array of 2 elements 708 708 */ 709 709 public synchronized Date[] getMinMaxTimeForAllTracks() { 710 double now = System.currentTimeMillis() / 1000.0;711 final DoubleSummaryStatistics statistics = tracks.stream()710 long now = System.currentTimeMillis(); 711 final LongSummaryStatistics statistics = tracks.stream() 712 712 .flatMap(trk -> trk.getSegments().stream()) 713 713 .flatMap(seg -> seg.getWayPoints().stream()) 714 .mapTo Double(pnt -> pnt.time)714 .mapToLong(pnt -> pnt.getTimeInMillis()) 715 715 .filter(t -> t > 0 && t <= now) 716 716 .summaryStatistics(); 717 717 return statistics.getCount() == 0 718 718 ? new Date[0] 719 : new Date[]{new Date( (long) (statistics.getMin() * 1000)), new Date((long) (statistics.getMax() * 1000))};719 : new Date[]{new Date(statistics.getMin()), new Date(statistics.getMax())}; 720 720 } 721 721 722 722 /** … … 754 754 755 755 double pnminsq = tolerance * tolerance; 756 756 EastNorth bestEN = null; 757 double bestTime = 0.0;757 Double bestTime = null; 758 758 double px = p.east(); 759 759 double py = p.north(); 760 760 double rx = 0.0, ry = 0.0, sx, sy, x, y; … … 773 773 if (pRsq < pnminsq) { 774 774 pnminsq = pRsq; 775 775 bestEN = en; 776 bestTime = r.time; 776 if (r.hasDate()) { 777 bestTime = r.getTime(); 778 } 777 779 } 778 780 } else { 779 781 sx = en.east(); … … 799 801 double nx = rx - rnoverRS * b; 800 802 double ny = ry + rnoverRS * a; 801 803 bestEN = new EastNorth(nx, ny); 802 bestTime = r.time + rnoverRS * (wpSeg.time - r.time); 804 if (r.hasDate() && wpSeg.hasDate()) { 805 bestTime = r.getTime() + rnoverRS * (wpSeg.getTime() - r.getTime()); 806 } 803 807 pnminsq = pnsq; 804 808 } 805 809 } … … 819 823 if (prsq < pnminsq) { 820 824 pnminsq = prsq; 821 825 bestEN = c; 822 bestTime = r.time; 826 if (r.hasDate()) { 827 bestTime = r.getTime(); 828 } 823 829 } 824 830 } 825 831 } … … 827 833 if (bestEN == null) 828 834 return null; 829 835 WayPoint best = new WayPoint(ProjectionRegistry.getProjection().eastNorth2latlon(bestEN)); 830 best.time = bestTime; 836 if (bestTime != null) { 837 best.setTimeInMillis((long) (bestTime * 1000)); 838 } 831 839 return best; 832 840 } 833 841 -
src/org/openstreetmap/josm/data/gpx/GpxImageCorrelation.java
45 45 //remove waypoints at the beginning of the track/segment without timestamps 46 46 int wp; 47 47 for (wp = 0; wp < wps.size(); wp++) { 48 if (wps.get(wp). setTimeFromAttribute() != null) {48 if (wps.get(wp).hasDate()) { 49 49 break; 50 50 } 51 51 } … … 61 61 segs.sort((o1, o2) -> { 62 62 if (o1.isEmpty() || o2.isEmpty()) 63 63 return 0; 64 return Double.compare(o1.get(0).time, o2.get(0).time);64 return o1.get(0).compareTo(o2.get(0)); 65 65 }); 66 66 trks.add(segs); 67 67 } … … 71 71 if (o1.isEmpty() || o1.get(0).isEmpty() 72 72 || o2.isEmpty() || o2.get(0).isEmpty()) 73 73 return 0; 74 return Double.compare(o1.get(0).get(0).time, o2.get(0).get(0).time);74 return o1.get(0).get(0).compareTo(o2.get(0).get(0)); 75 75 }); 76 76 77 77 boolean trkInt, trkTag, segInt, segTag; … … 110 110 List<WayPoint> wps = segs.get(s); 111 111 for (int i = 0; i < wps.size(); i++) { 112 112 WayPoint curWp = wps.get(i); 113 Date parsedTime = curWp.setTimeFromAttribute();114 113 // Interpolate timestamps in the segment, if one or more waypoints miss them 115 if ( parsedTime == null) {114 if (!curWp.hasDate()) { 116 115 //check if any of the following waypoints has a timestamp... 117 if (i > 0 && wps.get(i - 1). time != 0) {118 long prevWpTimeNoOffset = wps.get(i - 1).getTime ().getTime();116 if (i > 0 && wps.get(i - 1).hasDate()) { 117 long prevWpTimeNoOffset = wps.get(i - 1).getTimeInMillis(); 119 118 double totalDist = 0; 120 119 List<Pair<Double, WayPoint>> nextWps = new ArrayList<>(); 121 120 for (int j = i; j < wps.size(); j++) { 122 121 totalDist += wps.get(j - 1).getCoor().greatCircleDistance(wps.get(j).getCoor()); 123 122 nextWps.add(new Pair<>(totalDist, wps.get(j))); 124 final Date nextTime = wps.get(j).setTimeFromAttribute(); 125 if (nextTime != null) { 123 if (wps.get(j).hasDate()) { 126 124 // ...if yes, interpolate everything in between 127 long timeDiff = nextTime.getTime() - prevWpTimeNoOffset;125 long timeDiff = wps.get(j).getTimeInMillis() - prevWpTimeNoOffset; 128 126 for (Pair<Double, WayPoint> pair : nextWps) { 129 pair.b.setTime (new Date((long) (prevWpTimeNoOffset + (timeDiff * (pair.a / totalDist)))));127 pair.b.setTimeInMillis((long) (prevWpTimeNoOffset + (timeDiff * (pair.a / totalDist)))); 130 128 } 131 129 break; 132 130 } 133 131 } 134 parsedTime = curWp.setTimeFromAttribute(); 135 if (parsedTime == null) { 132 if (!curWp.hasDate()) { 136 133 break; //It's pointless to continue with this segment, because none of the following waypoints had a timestamp 137 134 } 138 135 } else { … … 141 138 } 142 139 } 143 140 144 final long curWpTime = parsedTime.getTime() + offset;141 final long curWpTime = curWp.getTimeInMillis() + offset; 145 142 boolean interpolate = true; 146 143 int tagTime = 0; 147 144 if (i == 0) { -
src/org/openstreetmap/josm/data/gpx/WayPoint.java
4 4 import java.awt.Color; 5 5 import java.util.ArrayList; 6 6 import java.util.Date; 7 import java.util.HashMap; 7 8 import java.util.List; 8 9 import java.util.Objects; 9 10 … … 13 14 import org.openstreetmap.josm.data.osm.search.SearchCompiler.Match; 14 15 import org.openstreetmap.josm.data.projection.Projecting; 15 16 import org.openstreetmap.josm.tools.Logging; 17 import org.openstreetmap.josm.tools.date.DateUtils; 16 18 import org.openstreetmap.josm.tools.template_engine.TemplateEngineDataProvider; 17 19 18 20 /** … … 22 24 public class WayPoint extends WithAttributes implements Comparable<WayPoint>, TemplateEngineDataProvider, ILatLon { 23 25 24 26 /** 25 * The seconds (not milliseconds!) since 1970-01-01 00:00 UTC26 */27 public double time;28 /**29 27 * The color to draw the segment before this point in 30 28 * @see #drawLine 31 29 */ 32 30 public Color customColoring; 31 33 32 /** 34 33 * <code>true</code> indicates that the line before this point should be drawn 35 34 */ 36 35 public boolean drawLine; 36 37 37 /** 38 38 * The direction of the line before this point. Used as cache to speed up drawing. Should not be relied on. 39 39 */ 40 40 public int dir; 41 41 42 /* 43 * We "inline" lat/lon, rather than usinga LatLon internally => reduces memory overhead. Relevant 44 * because a lot of GPX waypoints are created when GPS tracks are downloaded from the OSM server. 45 */ 46 private final double lat; 47 private final double lon; 48 49 /* 50 * internal cache of projected coordinates 51 */ 52 private double east = Double.NaN; 53 private double north = Double.NaN; 54 private Object eastNorthCacheKey; 55 42 56 /** 43 57 * Constructs a new {@code WayPoint} from an existing one. 58 * 59 * Except for PT_TIME attribute, all attribute objects are 60 * shallow copied. This means modification of attr objects 61 * will affect original and new {@code WayPoint}. 62 * 44 63 * @param p existing waypoint 45 64 */ 46 65 public WayPoint(WayPoint p) { 66 init_attr(); 47 67 attr.putAll(p.attr); 68 attr.put(PT_TIME, p.getDate()); 48 69 lat = p.lat; 49 70 lon = p.lon; 50 71 east = p.east; 51 72 north = p.north; 52 73 eastNorthCacheKey = p.eastNorthCacheKey; 53 time = p.time;54 74 customColoring = p.customColoring; 55 75 drawLine = p.drawLine; 56 76 dir = p.dir; … … 61 81 * @param ll lat/lon coordinates 62 82 */ 63 83 public WayPoint(LatLon ll) { 84 init_attr(); 64 85 lat = ll.lat(); 65 86 lon = ll.lon(); 66 87 } 67 88 68 /* 69 * We "inline" lat/lon, rather than usinga LatLon internally => reduces memory overhead. Relevant 70 * because a lot of GPX waypoints are created when GPS tracks are downloaded from the OSM server. 71 */ 72 private final double lat; 73 private final double lon; 74 75 /* 76 * internal cache of projected coordinates 89 /** 90 * Interim to detect legacy code that is not using {@code WayPoint.setTime(x)} 91 * functions, but {@code attr.put(PT_TIME, (String) x)} logic. 77 92 */ 78 private double east = Double.NaN; 79 private double north = Double.NaN; 80 private Object eastNorthCacheKey; 93 private void init_attr() { 94 attr = new HashMap<String, Object>(0) { 95 @Override 96 public Object put(String key, Object value) { 97 Object ret = null; 98 if (key != PT_TIME || (key == PT_TIME && value instanceof Date)) { 99 ret = super.put(key, value); 100 } else { 101 if (value instanceof String) { 102 ret = super.put(PT_TIME, DateUtils.fromString((String) value)); 103 if (!Logging.getLastErrorAndWarnings().get(0).contains("calling WayPoint.put")) { 104 StackTraceElement[] e = Thread.currentThread().getStackTrace(); 105 int n = 1; 106 while (n < e.length && e[n].getMethodName().equals("put")) 107 n++; 108 Logging.warn("{0}:{1} calling WayPoint.put(PT_TIME, ..) is deprecated. " + 109 "Use WayPoint.setTime(..) instead.", e[n].getClassName(), e[n].getMethodName()); 110 } 111 } 112 } 113 return ret; 114 } 115 }; 116 } 81 117 82 118 /** 83 119 * Invalidate the internal cache of east/north coordinates. … … 125 161 } 126 162 127 163 /** 128 * Sets the {@link # time} field as well as the {@link #PT_TIME} attribute to the specified time.164 * Sets the {@link #PT_TIME} attribute to the specified time. 129 165 * 130 * @param time the time to set166 * @param date the time to set 131 167 * @since 9383 132 168 */ 133 public void setTime(Date time) { 134 this.time = time.getTime() / 1000.; 135 this.attr.put(PT_TIME, time); 169 public void setTime(Date date) { 170 setTimeInMillis(date.getTime()); 136 171 } 137 172 138 173 /** 139 * Convert the time stamp of the waypoint into seconds from the epoch. 140 * 141 * @deprecated call {@link #setTimeFromAttribute()} directly if you need this 142 */ 143 @Deprecated 144 public void setTime() { 145 setTimeFromAttribute(); 146 } 147 148 /** 149 * Sets the {@link #time} field as well as the {@link #PT_TIME} attribute to the specified time. 174 * Sets the {@link #PT_TIME} attribute to the specified time. 150 175 * 151 176 * @param ts seconds from the epoch 152 177 * @since 13210 153 178 */ 154 179 public void setTime(long ts) { 155 setTimeInMillis(ts *1000);180 setTimeInMillis(ts * 1000); 156 181 } 157 182 158 183 /** 159 * Sets the {@link # time} field as well as the {@link #PT_TIME} attribute to the specified time.184 * Sets the {@link #PT_TIME} attribute to the specified time. 160 185 * 161 186 * @param ts milliseconds from the epoch 162 187 * @since 14434 163 188 */ 164 189 public void setTimeInMillis(long ts) { 165 this.time = ts / 1000.; 166 this.attr.put(PT_TIME, new Date(ts)); 190 attr.put(PT_TIME, new Date(ts)); 191 } 192 193 @Override 194 public int compareTo(WayPoint other) { 195 return Long.compare(getTimeInMillis(), other.getTimeInMillis()); 167 196 } 168 197 169 198 /** 170 * Convert the time stamp of the waypoint into seconds from the epoch171 * @return The parsed time if successful, or {@code null}172 * @ since 9383199 * Returns the waypoint time in seconds since the epoch. 200 * 201 * @return the waypoint time 173 202 */ 174 public Date setTimeFromAttribute() { 175 if (attr.containsKey(PT_TIME)) { 176 final Object obj = get(PT_TIME); 203 public double getTime() { 204 return getTimeInMillis() / 1000.; 205 } 206 207 /** 208 * Returns the waypoint time in milliseconds since the epoch. 209 * 210 * @return the waypoint time 211 */ 212 public long getTimeInMillis() { 213 Date d = getDateImpl(); 214 return d == null ? 0 : d.getTime(); 215 } 216 217 /** 218 * Returns true if this waypoint has a time. 219 * 220 * @return true if a time is set, false otherwise 221 */ 222 public boolean hasDate() { 223 return attr.get(PT_TIME) instanceof Date; 224 } 225 226 /** 227 * Returns the waypoint time Date object. 228 * 229 * @return a copy of the Date object associated with this waypoint 230 */ 231 public Date getDate() { 232 return DateUtils.cloneDate(getDateImpl()); 233 } 234 235 /** 236 * Returns the waypoint time Date object. 237 * 238 * @return the Date object associated with this waypoint 239 */ 240 private Date getDateImpl() { 241 Date ret = null; 242 243 try { 244 final Object obj = attr.get(PT_TIME); 245 177 246 if (obj instanceof Date) { 178 final Date date = (Date) obj; 179 time = date.getTime() / 1000.; 180 return date; 247 ret = (Date) obj; 181 248 } else if (obj == null) { 182 249 Logging.info("Waypoint {0} value unset", PT_TIME); 183 250 } else { 184 251 Logging.warn("Unsupported waypoint {0} value: {1}", PT_TIME, obj); 185 time = 0;186 252 } 253 } catch (NullPointerException e) { 254 // satisfies WayPointTest.testEqualsContract() 187 255 } 188 return null;189 }190 256 191 @Override 192 public int compareTo(WayPoint w) { 193 return Double.compare(time, w.time); 194 } 195 196 /** 197 * Returns the waypoint time. 198 * @return the waypoint time 199 */ 200 public Date getTime() { 201 return new Date((long) (time * 1000)); 257 return ret; 202 258 } 203 259 204 260 @Override … … 227 283 result = prime * result + (int) (temp ^ (temp >>> 32)); 228 284 temp = Double.doubleToLongBits(lon); 229 285 result = prime * result + (int) (temp ^ (temp >>> 32)); 230 temp = Double.doubleToLongBits(time);286 temp = getTimeInMillis(); 231 287 result = prime * result + (int) (temp ^ (temp >>> 32)); 232 288 return result; 233 289 } … … 241 297 WayPoint other = (WayPoint) obj; 242 298 return Double.doubleToLongBits(lat) == Double.doubleToLongBits(other.lat) 243 299 && Double.doubleToLongBits(lon) == Double.doubleToLongBits(other.lon) 244 && Double.doubleToLongBits(time) == Double.doubleToLongBits(other.time); 300 && getTimeInMillis() == other.getTimeInMillis(); 301 } 302 303 /** 304 * Convert the time stamp of the waypoint into seconds from the epoch. 305 * 306 * @deprecated 307 */ 308 @Deprecated 309 public void setTime() { 310 setTimeFromAttribute(); 311 } 312 313 /** 314 * Convert the time stamp of the waypoint into seconds from the epoch. 315 * @return The parsed time if successful, or {@code null} 316 * @since 9383 317 * 318 * @deprecated 319 */ 320 @Deprecated 321 public Date setTimeFromAttribute() { 322 Logging.warn("WayPoint.setTimeFromAttribute() is deprecated, please fix calling code"); 323 return getDate(); 245 324 } 246 325 } -
src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
800 800 if (time > Long.MIN_VALUE) { 801 801 wpt.setTimeInMillis(time); 802 802 } else if (n.hasKey(GpxConstants.PT_TIME)) { 803 wpt.setTime (DateUtils.fromString(n.get(GpxConstants.PT_TIME)));803 wpt.setTimeInMillis(DateUtils.tsFromString(n.get(GpxConstants.PT_TIME))); 804 804 } else if (!n.isTimestampEmpty()) { 805 805 wpt.setTime(Integer.toUnsignedLong(n.getRawTimestamp())); 806 806 } -
src/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImages.java
1229 1229 outer: for (GpxTrack trk : gpx.tracks) { 1230 1230 for (GpxTrackSegment segment : trk.getSegments()) { 1231 1231 for (WayPoint curWp : segment.getWayPoints()) { 1232 final Date parsedTime = curWp.setTimeFromAttribute(); 1233 if (parsedTime != null) { 1234 firstGPXDate = parsedTime.getTime(); 1232 if (curWp.hasDate()) { 1233 firstGPXDate = curWp.getTimeInMillis(); 1235 1234 break outer; 1236 1235 } 1237 1236 } -
src/org/openstreetmap/josm/gui/layer/gpx/GpxDrawHelper.java
508 508 if (!trkPnt.isLatLonKnown()) { 509 509 continue; 510 510 } 511 if (oldWp != null && trkPnt. time > oldWp.time) {511 if (oldWp != null && trkPnt.getTimeInMillis() > oldWp.getTimeInMillis()) { 512 512 double vel = trkPnt.getCoor().greatCircleDistance(oldWp.getCoor()) 513 / (trkPnt. time - oldWp.time);513 / (trkPnt.getTime() - oldWp.getTime()); 514 514 velocities.add(vel); 515 515 } 516 516 oldWp = trkPnt; … … 586 586 boolean noDraw = false; 587 587 switch (colored) { 588 588 case VELOCITY: 589 double dtime = trkPnt. time - oldWp.time;589 double dtime = trkPnt.getTime() - oldWp.getTime(); 590 590 if (dtime > 0) { 591 591 color = velocityScale.getColor(dist / dtime); 592 592 } else { … … 598 598 color = directionScale.getColor(dirColor); 599 599 break; 600 600 case TIME: 601 double t = trkPnt. time;601 double t = trkPnt.getTime(); 602 602 // skip bad timestamps and very short tracks 603 603 if (t > 0 && t <= now && maxval - minval > minTrackDurationForTimeColoring) { 604 604 color = dateScale.getColor(t); -
src/org/openstreetmap/josm/gui/layer/gpx/ImportAudioAction.java
149 149 for (GpxTrack track : layer.data.tracks) { 150 150 for (GpxTrackSegment seg : track.getSegments()) { 151 151 for (WayPoint w : seg.getWayPoints()) { 152 firstTime = w. time;152 firstTime = w.getTime(); 153 153 break; 154 154 } 155 155 if (firstTime >= 0.0) { … … 174 174 // (a) try explicit timestamped waypoints - unless suppressed 175 175 if (hasWaypoints && Config.getPref().getBoolean("marker.audiofromexplicitwaypoints", true)) { 176 176 for (WayPoint w : layer.data.waypoints) { 177 if (w. time> firstTime) {177 if (w.getTime() > firstTime) { 178 178 waypoints.add(w); 179 } else if (w. time> 0.0) {179 } else if (w.getTime() > 0.0) { 180 180 timedMarkersOmitted = true; 181 181 } 182 182 } … … 191 191 WayPoint wNear = layer.data.nearestPointOnTrack(w.getEastNorth(ProjectionRegistry.getProjection()), snapDistance); 192 192 if (wNear != null) { 193 193 WayPoint wc = new WayPoint(w.getCoor()); 194 wc. time = wNear.time;194 wc.setTimeInMillis(wNear.getTimeInMillis()); 195 195 if (w.attr.containsKey(GpxConstants.GPX_NAME)) { 196 196 wc.put(GpxConstants.GPX_NAME, w.getString(GpxConstants.GPX_NAME)); 197 197 } … … 229 229 for (GpxTrack track : layer.data.tracks) { 230 230 for (GpxTrackSegment seg : track.getSegments()) { 231 231 for (WayPoint w : seg.getWayPoints()) { 232 if (startTime < w. time) {232 if (startTime < w.getTime()) { 233 233 w2 = w; 234 234 break; 235 235 } … … 245 245 timedMarkersOmitted = true; 246 246 } else { 247 247 wayPointFromTimeStamp = new WayPoint(w1.getCoor().interpolate(w2.getCoor(), 248 (startTime - w1. time) / (w2.time - w1.time)));249 wayPointFromTimeStamp. time = startTime;248 (startTime - w1.getTime()) / (w2.getTime() - w1.getTime()))); 249 wayPointFromTimeStamp.setTimeInMillis((long) (startTime * 1000)); 250 250 String name = audioFile.getName(); 251 251 int dot = name.lastIndexOf('.'); 252 252 if (dot > 0) { … … 267 267 for (WayPoint w : seg.getWayPoints()) { 268 268 WayPoint wStart = new WayPoint(w.getCoor()); 269 269 wStart.put(GpxConstants.GPX_NAME, "start"); 270 wStart. time = w.time;270 wStart.setTimeInMillis(w.getTimeInMillis()); 271 271 waypoints.add(wStart); 272 272 gotOne = true; 273 273 break; … … 283 283 } 284 284 285 285 // we must have got at least one waypoint now 286 ((ArrayList<WayPoint>) waypoints).sort( Comparator.comparingDouble(o -> o.time));286 ((ArrayList<WayPoint>) waypoints).sort((wp, other) -> wp.compareTo(other)); 287 287 288 288 firstTime = -1.0; // this time of the first waypoint, not first trackpoint 289 289 for (WayPoint w : waypoints) { 290 290 if (firstTime < 0.0) { 291 firstTime = w. time;291 firstTime = w.getTime(); 292 292 } 293 double offset = w. time- firstTime;294 AudioMarker am = new AudioMarker(w.getCoor(), w, url, ml, w. time, offset);293 double offset = w.getTime() - firstTime; 294 AudioMarker am = new AudioMarker(w.getCoor(), w, url, ml, w.getTime(), offset); 295 295 // timeFromAudio intended for future use to shift markers of this type on synchronization 296 296 if (w == wayPointFromTimeStamp) { 297 297 am.timeFromAudio = true; -
src/org/openstreetmap/josm/gui/layer/markerlayer/Marker.java
255 255 */ 256 256 public WayPoint convertToWayPoint() { 257 257 WayPoint wpt = new WayPoint(getCoor()); 258 wpt.setTime ((long) (time*1000));258 wpt.setTimeInMillis((long) (time * 1000)); 259 259 if (text != null) { 260 260 wpt.addExtension("text", text); 261 261 } else if (dataProvider != null) { -
src/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayer.java
96 96 97 97 for (WayPoint wpt : indata.waypoints) { 98 98 /* calculate time differences in waypoints */ 99 double time = wpt. time;99 double time = wpt.getTime(); 100 100 boolean wptHasLink = wpt.attr.containsKey(GpxConstants.META_LINKS); 101 101 if (firstTime < 0 && wptHasLink) { 102 102 firstTime = time; -
src/org/openstreetmap/josm/gui/layer/markerlayer/PlayHeadMarker.java
166 166 for (Marker m : recent.parentLayer.data) { 167 167 if (m instanceof AudioMarker) { 168 168 AudioMarker a = (AudioMarker) m; 169 if (a.time > cw. time) {169 if (a.time > cw.getTime()) { 170 170 break; 171 171 } 172 172 ca = a; … … 187 187 } else { 188 188 if (cw != null) { 189 189 setCoor(cw.getCoor()); 190 ca.play(cw. time- ca.time);190 ca.play(cw.getTime() - ca.time); 191 191 } 192 192 endDrag(false); 193 193 } … … 244 244 endDrag(true); 245 245 return; 246 246 } 247 ca = recent.parentLayer.addAudioMarker(cw. time, cw.getCoor());247 ca = recent.parentLayer.addAudioMarker(cw.getTime(), cw.getCoor()); 248 248 } 249 249 250 250 /* Actually do the synchronization */ … … 329 329 for (GpxTrack track : trackLayer.data.getTracks()) { 330 330 for (GpxTrackSegment trackseg : track.getSegments()) { 331 331 for (WayPoint w: trackseg.getWayPoints()) { 332 if (audioTime < w. time) {332 if (audioTime < w.getTime()) { 333 333 w2 = w; 334 334 break; 335 335 } … … 349 349 setEastNorth(w2 == null ? 350 350 w1.getEastNorth(ProjectionRegistry.getProjection()) : 351 351 w1.getEastNorth(ProjectionRegistry.getProjection()).interpolate(w2.getEastNorth(ProjectionRegistry.getProjection()), 352 (audioTime - w1. time)/(w2.time - w1.time)));352 (audioTime - w1.getTime())/(w2.getTime() - w1.getTime()))); 353 353 time = audioTime; 354 354 MapView mapView = MainApplication.getMap().mapView; 355 355 if (jumpToMarker) { -
src/org/openstreetmap/josm/io/GpxReader.java
444 444 currentWayPoint.put(localName, 0f); 445 445 } 446 446 break; 447 case GpxConstants.PT_TIME:447 case PT_TIME: 448 448 try { 449 currentWayPoint.setTime (DateUtils.fromString(accumulator.toString()));449 currentWayPoint.setTimeInMillis(DateUtils.tsFromString(accumulator.toString())); 450 450 } catch (UncheckedParseException e) { 451 451 Logging.error(e); 452 452 } -
src/org/openstreetmap/josm/io/nmea/NmeaReader.java
524 524 ps.pDate = currentDate; 525 525 if (ps.pWp != currentwp) { 526 526 if (ps.pWp != null) { 527 ps.pWp. setTimeFromAttribute();527 ps.pWp.getDate(); 528 528 } 529 529 ps.pWp = currentwp; 530 530 ps.waypoints.add(currentwp); -
test/unit/org/openstreetmap/josm/io/nmea/NmeaReaderTest.java
69 69 assertEquals(DateUtils.fromString("2016-01-25T05:05:09.200Z"), wayPoints.get(0).get(GpxConstants.PT_TIME)); 70 70 assertEquals(DateUtils.fromString("2016-01-25T05:05:09.400Z"), wayPoints.get(1).get(GpxConstants.PT_TIME)); 71 71 assertEquals(DateUtils.fromString("2016-01-25T05:05:09.600Z"), wayPoints.get(2).get(GpxConstants.PT_TIME)); 72 assertEquals(wayPoints.get(0).get Time(), wayPoints.get(0).get(GpxConstants.PT_TIME));72 assertEquals(wayPoints.get(0).getDate(), wayPoints.get(0).get(GpxConstants.PT_TIME)); 73 73 74 assertEquals("2016-01-25T05:05:09.200Z", iso8601.format(wayPoints.get(0).get Time()));75 assertEquals("2016-01-25T05:05:09.400Z", iso8601.format(wayPoints.get(1).get Time()));76 assertEquals("2016-01-25T05:05:09.600Z", iso8601.format(wayPoints.get(2).get Time()));74 assertEquals("2016-01-25T05:05:09.200Z", iso8601.format(wayPoints.get(0).getDate())); 75 assertEquals("2016-01-25T05:05:09.400Z", iso8601.format(wayPoints.get(1).getDate())); 76 assertEquals("2016-01-25T05:05:09.600Z", iso8601.format(wayPoints.get(2).getDate())); 77 77 78 78 assertEquals(new LatLon(46.98807, -1.400525), wayPoints.get(0).getCoor()); 79 79 assertEquals("38.9", wayPoints.get(0).get(GpxConstants.PT_ELE)); … … 170 170 } 171 171 172 172 private static Date readDate(String nmeaLine) throws IOException, SAXException { 173 return readWayPoint(nmeaLine).get Time();173 return readWayPoint(nmeaLine).getDate(); 174 174 } 175 175 176 176 private static double readSpeed(String nmeaLine) throws IOException, SAXException {