Changeset 17749 in josm for trunk/src/org


Ignore:
Timestamp:
2021-04-11T21:56:50+02:00 (3 years ago)
Author:
simon04
Message:

see #14176 - Migrate OsmPrimitive to Instant

Location:
trunk/src/org/openstreetmap/josm
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmChangeTask.java

    r16453 r17749  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import java.time.Instant;
    67import java.util.Arrays;
    78import java.util.Date;
     
    112113                // A changeset does not contain all referred primitives, this is the map of incomplete ones
    113114                // For each incomplete primitive, we'll have to get its state at date it was referred
    114                 Map<OsmPrimitive, Date> toLoad = new HashMap<>();
     115                Map<OsmPrimitive, Instant> toLoad = new HashMap<>();
    115116                for (OsmPrimitive p : downloadedData.allNonDeletedPrimitives()) {
    116117                    if (p.isIncomplete()) {
    117                         Date timestamp = p.getReferrers().stream()
     118                        Instant timestamp = p.getReferrers().stream()
    118119                                .filter(ref -> !ref.isTimestampEmpty())
    119120                                .findFirst()
    120                                 .map(AbstractPrimitive::getTimestamp)
     121                                .map(AbstractPrimitive::getInstant)
    121122                                .orElse(null);
    122123                        toLoad.put(p, timestamp);
     
    138139    private static final class HistoryLoaderAndListener extends HistoryLoadTask implements HistoryDataSetListener {
    139140
    140         private final Map<OsmPrimitive, Date> toLoad;
    141 
    142         private HistoryLoaderAndListener(Map<OsmPrimitive, Date> toLoad) {
     141        private final Map<OsmPrimitive, Instant> toLoad;
     142
     143        private HistoryLoaderAndListener(Map<OsmPrimitive, Instant> toLoad) {
    143144            this.toLoad = toLoad;
    144145            this.setChangesetDataNeeded(false);
     
    150151        @Override
    151152        public void historyUpdated(HistoryDataSet source, PrimitiveId id) {
    152             Map<OsmPrimitive, Date> toLoadNext = new HashMap<>();
    153             for (Iterator<Entry<OsmPrimitive, Date>> it = toLoad.entrySet().iterator(); it.hasNext();) {
    154                 Entry<OsmPrimitive, Date> entry = it.next();
     153            Map<OsmPrimitive, Instant> toLoadNext = new HashMap<>();
     154            for (Iterator<Entry<OsmPrimitive, Instant>> it = toLoad.entrySet().iterator(); it.hasNext();) {
     155                Entry<OsmPrimitive, Instant> entry = it.next();
    155156                OsmPrimitive p = entry.getKey();
    156157                History history = source.getHistory(p.getPrimitiveId());
    157                 Date date = entry.getValue();
     158                Instant date = entry.getValue();
    158159                // If the history has been loaded and a timestamp is known
    159160                if (history != null && date != null) {
    160161                    // Lookup for the primitive version at the specified timestamp
    161                     HistoryOsmPrimitive hp = history.getByDate(date);
     162                    HistoryOsmPrimitive hp = history.getByDate(Date.from(date));
    162163                    if (hp != null) {
    163164                        PrimitiveData data;
  • trunk/src/org/openstreetmap/josm/data/osm/AbstractPrimitive.java

    r17589 r17749  
    55
    66import java.text.MessageFormat;
     7import java.time.Instant;
    78import java.util.Arrays;
    89import java.util.Collection;
     
    297298    }
    298299
     300    @Deprecated
    299301    @Override
    300302    public void setTimestamp(Date timestamp) {
     
    303305
    304306    @Override
     307    public void setInstant(Instant timestamp) {
     308        this.timestamp = (int) timestamp.getEpochSecond();
     309    }
     310
     311    @Override
    305312    public void setRawTimestamp(int timestamp) {
    306313        this.timestamp = timestamp;
    307314    }
    308315
     316    @Deprecated
    309317    @Override
    310318    public Date getTimestamp() {
    311         return new Date(TimeUnit.SECONDS.toMillis(Integer.toUnsignedLong(timestamp)));
     319        return Date.from(getInstant());
     320    }
     321
     322    @Override
     323    public Instant getInstant() {
     324        return Instant.ofEpochSecond(Integer.toUnsignedLong(timestamp));
    312325    }
    313326
  • trunk/src/org/openstreetmap/josm/data/osm/Changeset.java

    r17717 r17749  
    103103        final Changeset changeset = new Changeset(primitive.getChangesetId());
    104104        changeset.setUser(primitive.getUser());
    105         changeset.setCreatedAt(primitive.getTimestamp().toInstant()); // not accurate in all cases
     105        changeset.setCreatedAt(primitive.getInstant()); // not accurate in all cases
    106106        return changeset;
    107107    }
  • trunk/src/org/openstreetmap/josm/data/osm/IPrimitive.java

    r17459 r17749  
    22package org.openstreetmap.josm.data.osm;
    33
     4import java.time.Instant;
    45import java.util.Date;
    56import java.util.List;
     
    276277     * @return date of last modification
    277278     * @see #setTimestamp
    278      */
     279     * @deprecated Use {@link #getInstant}
     280     */
     281    @Deprecated
    279282    Date getTimestamp();
    280283
     
    284287     * used to check against edit conflicts.
    285288     *
     289     * @return date of last modification
     290     * @see #getInstant
     291     */
     292    Instant getInstant();
     293
     294    /**
     295     * Time of last modification to this object. This is not set by JOSM but
     296     * read from the server and delivered back to the server unmodified. It is
     297     * used to check against edit conflicts.
     298     *
    286299     * @return last modification as timestamp
    287300     * @see #setRawTimestamp
     
    293306     * @param timestamp date of last modification
    294307     * @see #getTimestamp
    295      */
     308     * @deprecated Use {@link #setInstant}
     309     */
     310    @Deprecated
    296311    void setTimestamp(Date timestamp);
     312
     313    /**
     314     * Sets time of last modification to this object
     315     * @param timestamp date of last modification
     316     * @see #getInstant
     317     */
     318    void setInstant(Instant timestamp);
    297319
    298320    /**
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r17584 r17749  
    301301    }
    302302
     303    @Deprecated
    303304    @Override
    304305    public void setTimestamp(Date timestamp) {
  • trunk/src/org/openstreetmap/josm/data/osm/history/HistoryOsmPrimitive.java

    r16913 r17749  
    9696     */
    9797    protected HistoryOsmPrimitive(OsmPrimitive p) {
    98         this(p.getId(), p.getVersion(), p.isVisible(), p.getUser(), p.getChangesetId(), p.getTimestamp());
     98        this(p.getId(), p.getVersion(), p.isVisible(), p.getUser(), p.getChangesetId(), Date.from(p.getInstant()));
    9999    }
    100100
     
    364364            Logging.log(Logging.LEVEL_ERROR, "Cannot change visibility for "+data+':', e);
    365365        }
    366         data.setTimestamp(timestamp);
     366        data.setInstant(timestamp.toInstant());
    367367        data.setKeys(tags);
    368368        data.setOsmId(id, (int) version);
  • trunk/src/org/openstreetmap/josm/data/osm/search/SearchCompiler.java

    r17747 r17749  
    741741            String mv;
    742742            if ("timestamp".equals(key) && osm instanceof OsmPrimitive) {
    743                 mv = DateUtils.fromTimestamp(((OsmPrimitive) osm).getRawTimestamp());
     743                mv = ((OsmPrimitive) osm).getInstant().toString();
    744744            } else {
    745745                mv = osm.get(key);
     
    14931493            try {
    14941494                // if min timestamp is empty: use lowest possible date
    1495                 minDate = DateUtils.fromString(rangeA1.isEmpty() ? "1980" : rangeA1).getTime();
     1495                minDate = DateUtils.parseInstant(rangeA1.isEmpty() ? "1980" : rangeA1).toEpochMilli();
    14961496            } catch (UncheckedParseException | DateTimeException ex) {
    14971497                throw new SearchParseError(tr("Cannot parse timestamp ''{0}''", rangeA1), ex);
     
    14991499            try {
    15001500                // if max timestamp is empty: use "now"
    1501                 maxDate = rangeA2.isEmpty() ? System.currentTimeMillis() : DateUtils.fromString(rangeA2).getTime();
     1501                maxDate = rangeA2.isEmpty() ? System.currentTimeMillis() : DateUtils.parseInstant(rangeA2).toEpochMilli();
    15021502            } catch (UncheckedParseException | DateTimeException ex) {
    15031503                throw new SearchParseError(tr("Cannot parse timestamp ''{0}''", rangeA2), ex);
     
    15081508        @Override
    15091509        protected Long getNumber(OsmPrimitive osm) {
    1510             return osm.getTimestamp().getTime();
     1510            return osm.getInstant().toEpochMilli();
    15111511        }
    15121512
  • trunk/src/org/openstreetmap/josm/gui/dialogs/InspectPrimitiveDataText.java

    r17585 r17749  
    154154        add(tr("Data Set: "), Integer.toHexString(o.getDataSet().hashCode()));
    155155        add(tr("Edited at: "), o.isTimestampEmpty() ? tr("<new object>")
    156                 : DateUtils.fromTimestamp(o.getRawTimestamp()));
     156                : o.getInstant().toString());
    157157        add(tr("Edited by: "), o.getUser() == null ? tr("<new object>")
    158158                : getNameAndId(o.getUser().getName(), o.getUser().getId()));
  • trunk/src/org/openstreetmap/josm/gui/history/VersionInfoPanel.java

    r14463 r17749  
    236236     */
    237237    public void update(final OsmPrimitive primitive, final boolean isLatest) {
    238         update(Changeset.fromPrimitive(primitive), isLatest, primitive.getTimestamp(), primitive.getVersion(), primitive.getPrimitiveId());
     238        Date timestamp = Date.from(primitive.getInstant());
     239        update(Changeset.fromPrimitive(primitive), isLatest, timestamp, primitive.getVersion(), primitive.getPrimitiveId());
    239240    }
    240241
  • trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r17715 r17749  
    2424import java.io.IOException;
    2525import java.time.DateTimeException;
    26 import java.time.Instant;
    2726import java.util.ArrayList;
    2827import java.util.Arrays;
     
    877876                wpt.setTimeInMillis(time);
    878877            } else if ((v = gpxVal(n, GpxConstants.PT_TIME)) != null) {
    879                 wpt.setTimeInMillis(DateUtils.tsFromString(v));
     878                wpt.setInstant(DateUtils.parseInstant(v));
    880879            } else if (!n.isTimestampEmpty()) {
    881                 wpt.setInstant(Instant.ofEpochSecond(Integer.toUnsignedLong(n.getRawTimestamp())));
     880                wpt.setInstant(n.getInstant());
    882881            }
    883882        } catch (UncheckedParseException | DateTimeException e) {
  • trunk/src/org/openstreetmap/josm/gui/layer/gpx/ConvertFromGpxLayerAction.java

    r17715 r17749  
    99import java.time.Instant;
    1010import java.util.ArrayList;
    11 import java.util.Date;
    1211import java.util.List;
    1312import java.util.Map;
     
    135134                    p.put(GpxConstants.GPX_PREFIX + key, String.valueOf(date));
    136135                }
    137                 p.setTimestamp(Date.from(date));
     136                p.setInstant(date);
    138137            }
    139138        }
  • trunk/src/org/openstreetmap/josm/io/AbstractReader.java

    r17166 r17749  
    431431        }
    432432        try {
    433             int timestamp = timestampCache.computeIfAbsent(time, t -> (int) (DateUtils.tsFromString(t) / 1000));
     433            int timestamp = timestampCache.computeIfAbsent(time, t -> (int) (DateUtils.parseInstant(t).getEpochSecond()));
    434434            current.setRawTimestamp(timestamp);
    435435        } catch (UncheckedParseException | DateTimeException e) {
  • trunk/src/org/openstreetmap/josm/io/DiffResultProcessor.java

    r17717 r17749  
    99import java.util.Collection;
    1010import java.util.Collections;
    11 import java.util.Date;
    1211import java.util.HashMap;
    1312import java.util.HashSet;
     
    153152                    // TODO is there a way to obtain the timestamp for non-closed changesets?
    154153                    Instant instant = Utils.firstNonNull(cs.getClosedAt(), Instant.now());
    155                     p.setTimestamp(Date.from(instant));
     154                    p.setInstant(instant);
    156155                }
    157156            }
  • trunk/src/org/openstreetmap/josm/io/OsmWriter.java

    r17717 r17749  
    366366            }
    367367            if (!osm.isTimestampEmpty()) {
    368                 out.print(" timestamp='"+DateUtils.fromTimestamp(osm.getRawTimestamp())+'\'');
     368                out.print(" timestamp='"+osm.getInstant()+'\'');
    369369            }
    370370            // user and visible added with 0.4 API
Note: See TracChangeset for help on using the changeset viewer.