Ignore:
Timestamp:
2018-11-27T21:40:10+01:00 (7 years ago)
Author:
Don-vip
Message:

fix #16995 - de-duplicate storage of timestamp within WayPoint and refactor some methods, added documentation, added some robustness against legacy code (will also log a warning if detected). Patch by cmuelle8, modified

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/gpx/GpxData.java

    r14451 r14456  
    99import java.util.Collections;
    1010import java.util.Date;
    11 import java.util.DoubleSummaryStatistics;
    1211import java.util.HashMap;
    1312import java.util.HashSet;
    1413import java.util.Iterator;
    1514import java.util.List;
     15import java.util.LongSummaryStatistics;
    1616import java.util.Map;
    1717import java.util.NoSuchElementException;
     
    175175                Date prevWpTime = null;
    176176                for (WayPoint wp : wpsOld) {
    177                     Date wpTime = wp.setTimeFromAttribute();
     177                    Date wpTime = wp.getDate();
    178178                    boolean overlap = false;
    179179                    if (wpTime != null) {
     
    267267
    268268        GpxTrackSegmentSpan(WayPoint a, WayPoint b) {
    269             Date at = a.getTime();
    270             Date bt = b.getTime();
     269            Date at = a.getDate();
     270            Date bt = b.getDate();
    271271            inv = bt.before(at);
    272272            if (inv) {
     
    324324            List<WayPoint> wps = new ArrayList<>(seg.getWayPoints());
    325325            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()) {
    327327                    return wps.get(i);
    328328                }
     
    691691     */
    692692    public static Date[] getMinMaxTimeForTrack(GpxTrack trk) {
    693         final DoubleSummaryStatistics statistics = trk.getSegments().stream()
     693        final LongSummaryStatistics statistics = trk.getSegments().stream()
    694694                .flatMap(seg -> seg.getWayPoints().stream())
    695                 .mapToDouble(pnt -> pnt.time)
     695                .mapToLong(pnt -> pnt.getTimeInMillis())
    696696                .summaryStatistics();
    697697        return statistics.getCount() == 0
    698698                ? 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())};
    700700    }
    701701
     
    708708    */
    709709    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()
    712712                .flatMap(trk -> trk.getSegments().stream())
    713713                .flatMap(seg -> seg.getWayPoints().stream())
    714                 .mapToDouble(pnt -> pnt.time)
     714                .mapToLong(pnt -> pnt.getTimeInMillis())
    715715                .filter(t -> t > 0 && t <= now)
    716716                .summaryStatistics();
    717717        return statistics.getCount() == 0
    718718                ? 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())};
    720720    }
    721721
     
    755755        double pnminsq = tolerance * tolerance;
    756756        EastNorth bestEN = null;
    757         double bestTime = 0.0;
     757        double bestTime = Double.NaN;
    758758        double px = p.east();
    759759        double py = p.north();
     
    774774                            pnminsq = pRsq;
    775775                            bestEN = en;
    776                             bestTime = r.time;
     776                            if (r.hasDate()) {
     777                                bestTime = r.getTime();
     778                            }
    777779                        }
    778780                    } else {
     
    800802                                double ny = ry + rnoverRS * a;
    801803                                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                                }
    803807                                pnminsq = pnsq;
    804808                            }
     
    820824                        pnminsq = prsq;
    821825                        bestEN = c;
    822                         bestTime = r.time;
     826                        if (r.hasDate()) {
     827                            bestTime = r.getTime();
     828                        }
    823829                    }
    824830                }
     
    828834            return null;
    829835        WayPoint best = new WayPoint(ProjectionRegistry.getProjection().eastNorth2latlon(bestEN));
    830         best.time = bestTime;
     836        if (!Double.isNaN(bestTime)) {
     837            best.setTimeInMillis((long) (bestTime * 1000));
     838        }
    831839        return best;
    832840    }
Note: See TracChangeset for help on using the changeset viewer.