Ignore:
Timestamp:
2021-04-08T22:56:06+02:00 (3 years ago)
Author:
simon04
Message:

see #14176 - Migrate GPX to Instant

File:
1 edited

Legend:

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

    r17439 r17715  
    44import java.io.File;
    55import java.text.MessageFormat;
     6import java.time.Instant;
    67import java.util.ArrayList;
    78import java.util.Arrays;
     
    910import java.util.Collections;
    1011import java.util.Comparator;
    11 import java.util.Date;
    1212import java.util.HashMap;
    1313import java.util.HashSet;
     
    200200                boolean split = false;
    201201                WayPoint prevLastOwnWp = null;
    202                 Date prevWpTime = null;
     202                Instant prevWpTime = null;
    203203                for (WayPoint wp : wpsOld) {
    204                     Date wpTime = wp.getDate();
     204                    Instant wpTime = wp.getInstant();
    205205                    boolean overlap = false;
    206206                    if (wpTime != null) {
    207207                        for (GpxTrackSegmentSpan ownspan : getSegmentSpans()) {
    208                             if (wpTime.after(ownspan.firstTime) && wpTime.before(ownspan.lastTime)) {
     208                            if (wpTime.isAfter(ownspan.firstTime) && wpTime.isBefore(ownspan.lastTime)) {
    209209                                overlap = true;
    210210                                if (connect) {
     
    219219                                break;
    220220                            } else if (connect && prevWpTime != null
    221                                     && prevWpTime.before(ownspan.firstTime)
    222                                     && wpTime.after(ownspan.lastTime)) {
     221                                    && prevWpTime.isBefore(ownspan.firstTime)
     222                                    && wpTime.isAfter(ownspan.lastTime)) {
    223223                                // the overlapping high priority track is shorter than the distance
    224224                                // between two waypoints of the low priority track
     
    287287    static class GpxTrackSegmentSpan {
    288288
    289         final Date firstTime;
    290         final Date lastTime;
     289        final Instant firstTime;
     290        final Instant lastTime;
    291291        private final boolean inv;
    292292        private final WayPoint firstWp;
     
    294294
    295295        GpxTrackSegmentSpan(WayPoint a, WayPoint b) {
    296             Date at = a.getDate();
    297             Date bt = b.getDate();
    298             inv = bt.before(at);
     296            Instant at = a.getInstant();
     297            Instant bt = b.getInstant();
     298            inv = bt.isBefore(at);
    299299            if (inv) {
    300300                firstWp = b;
     
    333333
    334334        boolean overlapsWith(GpxTrackSegmentSpan other) {
    335             return (firstTime.before(other.lastTime) && other.firstTime.before(lastTime))
    336                 || (other.firstTime.before(lastTime) && firstTime.before(other.lastTime));
     335            return (firstTime.isBefore(other.lastTime) && other.firstTime.isBefore(lastTime))
     336                || (other.firstTime.isBefore(lastTime) && firstTime.isBefore(other.lastTime));
    337337        }
    338338
     
    720720     * @return  minimum and maximum dates in array of 2 elements
    721721     */
    722     public static Date[] getMinMaxTimeForTrack(IGpxTrack trk) {
     722    public static Instant[] getMinMaxTimeForTrack(IGpxTrack trk) {
    723723        final LongSummaryStatistics statistics = trk.getSegments().stream()
    724724                .flatMap(seg -> seg.getWayPoints().stream())
     
    727727        return statistics.getCount() == 0 || (statistics.getMin() == 0 && statistics.getMax() == 0)
    728728                ? null
    729                 : new Date[]{new Date(statistics.getMin()), new Date(statistics.getMax())};
     729                : new Instant[]{Instant.ofEpochMilli(statistics.getMin()), Instant.ofEpochMilli(statistics.getMax())};
    730730    }
    731731
     
    737737    * @since 7319
    738738    */
    739     public synchronized Date[] getMinMaxTimeForAllTracks() {
     739    public synchronized Instant[] getMinMaxTimeForAllTracks() {
    740740        long now = System.currentTimeMillis();
    741741        final LongSummaryStatistics statistics = tracks.stream()
     
    746746                .summaryStatistics();
    747747        return statistics.getCount() == 0
    748                 ? new Date[0]
    749                 : new Date[]{new Date(statistics.getMin()), new Date(statistics.getMax())};
     748                ? new Instant[0]
     749                : new Instant[]{Instant.ofEpochMilli(statistics.getMin()), Instant.ofEpochMilli(statistics.getMax())};
    750750    }
    751751
Note: See TracChangeset for help on using the changeset viewer.