Changeset 17838 in josm for trunk/src/org


Ignore:
Timestamp:
2021-05-01T11:39:00+02:00 (4 years ago)
Author:
simon04
Message:

see #14176 - Migrate HistoryOsmPrimitive to Instant

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

Legend:

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

    r17749 r17838  
    66import java.time.Instant;
    77import java.util.Arrays;
    8 import java.util.Date;
    98import java.util.HashMap;
    109import java.util.Iterator;
     
    160159                if (history != null && date != null) {
    161160                    // Lookup for the primitive version at the specified timestamp
    162                     HistoryOsmPrimitive hp = history.getByDate(Date.from(date));
     161                    HistoryOsmPrimitive hp = history.getByDate(date);
    163162                    if (hp != null) {
    164163                        PrimitiveData data;
  • trunk/src/org/openstreetmap/josm/data/osm/history/History.java

    r17333 r17838  
    33
    44import java.text.MessageFormat;
     5import java.time.Instant;
    56import java.util.ArrayList;
    67import java.util.Comparator;
    7 import java.util.Date;
    88import java.util.List;
    99import java.util.stream.Collectors;
     
    8686     * @return a new partial copy of this history, from the given date
    8787     */
    88     public History from(final Date fromDate) {
    89         return filter(this, primitive -> primitive.getTimestamp().compareTo(fromDate) >= 0);
     88    public History from(final Instant fromDate) {
     89        return filter(this, primitive -> primitive.getInstant().compareTo(fromDate) >= 0);
    9090    }
    9191
     
    9595     * @return a new partial copy of this history, until the given date
    9696     */
    97     public History until(final Date untilDate) {
    98         return filter(this, primitive -> primitive.getTimestamp().compareTo(untilDate) <= 0);
     97    public History until(final Instant untilDate) {
     98        return filter(this, primitive -> primitive.getInstant().compareTo(untilDate) <= 0);
    9999    }
    100100
     
    105105     * @return a new partial copy of this history, between the given dates
    106106     */
    107     public History between(Date fromDate, Date untilDate) {
     107    public History between(Instant fromDate, Instant untilDate) {
    108108        return this.from(fromDate).until(untilDate);
    109109    }
     
    196196     * @return the history primitive at given <code>date</code>
    197197     */
    198     public HistoryOsmPrimitive getByDate(Date date) {
     198    public HistoryOsmPrimitive getByDate(Instant date) {
    199199        History h = sortAscending();
    200200
    201201        if (h.versions.isEmpty())
    202202            return null;
    203         if (h.get(0).getTimestamp().compareTo(date) > 0)
     203        if (h.get(0).getInstant().compareTo(date) > 0)
    204204            return null;
    205205        for (int i = 1; i < h.versions.size(); i++) {
    206             if (h.get(i-1).getTimestamp().compareTo(date) <= 0
    207                     && h.get(i).getTimestamp().compareTo(date) >= 0)
     206            if (h.get(i-1).getInstant().compareTo(date) <= 0
     207                    && h.get(i).getInstant().compareTo(date) >= 0)
    208208                return h.get(i);
    209209        }
  • trunk/src/org/openstreetmap/josm/data/osm/history/HistoryNode.java

    r11878 r17838  
    22package org.openstreetmap.josm.data.osm.history;
    33
    4 import java.util.Date;
     4import java.time.Instant;
    55
    66import org.openstreetmap.josm.data.coor.LatLon;
     
    3131     * @throws IllegalArgumentException if preconditions are violated
    3232     */
    33     public HistoryNode(long id, long version, boolean visible, User user, long changesetId, Date timestamp, LatLon coords) {
     33    public HistoryNode(long id, long version, boolean visible, User user, long changesetId, Instant timestamp, LatLon coords) {
    3434        this(id, version, visible, user, changesetId, timestamp, coords, true);
    3535    }
     
    5050     * @since 5440
    5151     */
    52     public HistoryNode(long id, long version, boolean visible, User user, long changesetId, Date timestamp, LatLon coords,
     52    public HistoryNode(long id, long version, boolean visible, User user, long changesetId, Instant timestamp, LatLon coords,
    5353            boolean checkHistoricParams) {
    5454        super(id, version, visible, user, changesetId, timestamp, checkHistoricParams);
  • trunk/src/org/openstreetmap/josm/data/osm/history/HistoryOsmPrimitive.java

    r17749 r17838  
    55
    66import java.text.MessageFormat;
     7import java.time.Instant;
    78import java.util.Collection;
    89import java.util.Collections;
     
    2526import org.openstreetmap.josm.tools.CheckParameterUtil;
    2627import org.openstreetmap.josm.tools.Logging;
    27 import org.openstreetmap.josm.tools.date.DateUtils;
    2828
    2929/**
     
    3838    private final long changesetId;
    3939    private Changeset changeset;
    40     private final Date timestamp;
     40    private final Instant timestamp;
    4141    private final long version;
    4242    private Map<String, String> tags;
     
    5454     * @throws IllegalArgumentException if preconditions are violated
    5555     */
    56     protected HistoryOsmPrimitive(long id, long version, boolean visible, User user, long changesetId, Date timestamp) {
     56    protected HistoryOsmPrimitive(long id, long version, boolean visible, User user, long changesetId, Instant timestamp) {
    5757        this(id, version, visible, user, changesetId, timestamp, true);
    5858    }
     
    7373     * @since 5440
    7474     */
    75     protected HistoryOsmPrimitive(long id, long version, boolean visible, User user, long changesetId, Date timestamp,
     75    protected HistoryOsmPrimitive(long id, long version, boolean visible, User user, long changesetId, Instant timestamp,
    7676            boolean checkHistoricParams) {
    7777        ensurePositiveLong(id, "id");
     
    8787        this.user = user;
    8888        this.changesetId = changesetId;
    89         this.timestamp = DateUtils.cloneDate(timestamp);
     89        this.timestamp = timestamp;
    9090        this.tags = new HashMap<>();
    9191    }
     
    9696     */
    9797    protected HistoryOsmPrimitive(OsmPrimitive p) {
    98         this(p.getId(), p.getVersion(), p.isVisible(), p.getUser(), p.getChangesetId(), Date.from(p.getInstant()));
     98        this(p.getId(), p.getVersion(), p.isVisible(), p.getUser(), p.getChangesetId(), p.getInstant());
    9999    }
    100100
     
    159159     * Returns the timestamp.
    160160     * @return the timestamp
    161      */
     161     * @deprecated Use {@link #getInstant()}
     162     */
     163    @Deprecated
    162164    public Date getTimestamp() {
    163         return DateUtils.cloneDate(timestamp);
     165        return Date.from(timestamp);
     166    }
     167
     168    /**
     169     * Returns the timestamp.
     170     * @return the timestamp
     171     */
     172    public Instant getInstant() {
     173        return timestamp;
    164174    }
    165175
     
    364374            Logging.log(Logging.LEVEL_ERROR, "Cannot change visibility for "+data+':', e);
    365375        }
    366         data.setInstant(timestamp.toInstant());
     376        data.setInstant(timestamp);
    367377        data.setKeys(tags);
    368378        data.setOsmId(id, (int) version);
  • trunk/src/org/openstreetmap/josm/data/osm/history/HistoryRelation.java

    r11878 r17838  
    33
    44import java.text.MessageFormat;
     5import java.time.Instant;
    56import java.util.ArrayList;
    67import java.util.Collections;
    7 import java.util.Date;
    88import java.util.List;
    99
     
    3535     * @throws IllegalArgumentException if preconditions are violated
    3636     */
    37     public HistoryRelation(long id, long version, boolean visible, User user, long changesetId, Date timestamp) {
     37    public HistoryRelation(long id, long version, boolean visible, User user, long changesetId, Instant timestamp) {
    3838        super(id, version, visible, user, changesetId, timestamp);
    3939    }
     
    5353     * @since 5440
    5454     */
    55     public HistoryRelation(long id, long version, boolean visible, User user, long changesetId, Date timestamp, boolean checkHistoricParams) {
     55    public HistoryRelation(long id, long version, boolean visible, User user, long changesetId, Instant timestamp, boolean checkHistoricParams) {
    5656        super(id, version, visible, user, changesetId, timestamp, checkHistoricParams);
    5757    }
     
    7070     * @throws IllegalArgumentException if preconditions are violated
    7171     */
    72     public HistoryRelation(long id, long version, boolean visible, User user, long changesetId, Date timestamp,
     72    public HistoryRelation(long id, long version, boolean visible, User user, long changesetId, Instant timestamp,
    7373            List<RelationMemberData> members) {
    7474        this(id, version, visible, user, changesetId, timestamp);
  • trunk/src/org/openstreetmap/josm/data/osm/history/HistoryWay.java

    r15121 r17838  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import java.time.Instant;
    67import java.util.ArrayList;
    78import java.util.Collections;
    8 import java.util.Date;
    99import java.util.List;
    1010import java.util.Objects;
     
    3535     * @throws IllegalArgumentException if preconditions are violated
    3636     */
    37     public HistoryWay(long id, long version, boolean visible, User user, long changesetId, Date timestamp) {
     37    public HistoryWay(long id, long version, boolean visible, User user, long changesetId, Instant timestamp) {
    3838        super(id, version, visible, user, changesetId, timestamp);
    3939    }
     
    5353     * @since 5440
    5454     */
    55     public HistoryWay(long id, long version, boolean visible, User user, long changesetId, Date timestamp, boolean checkHistoricParams) {
     55    public HistoryWay(long id, long version, boolean visible, User user, long changesetId, Instant timestamp, boolean checkHistoricParams) {
    5656        super(id, version, visible, user, changesetId, timestamp, checkHistoricParams);
    5757    }
     
    6969     * @throws IllegalArgumentException if preconditions are violated
    7070     */
    71     public HistoryWay(long id, long version, boolean visible, User user, long changesetId, Date timestamp, List<Long> nodeIdList) {
     71    public HistoryWay(long id, long version, boolean visible, User user, long changesetId, Instant timestamp, List<Long> nodeIdList) {
    7272        this(id, version, visible, user, changesetId, timestamp);
    7373        CheckParameterUtil.ensureParameterNotNull(nodeIdList, "nodeIdList");
  • trunk/src/org/openstreetmap/josm/gui/history/VersionInfoPanel.java

    r17749 r17838  
    1111import java.awt.Insets;
    1212import java.awt.event.ActionEvent;
    13 import java.text.DateFormat;
     13import java.time.Instant;
     14import java.time.format.FormatStyle;
    1415import java.util.Collections;
    15 import java.util.Date;
    1616
    1717import javax.swing.AbstractAction;
     
    170170    }
    171171
    172     protected String getInfoText(final Date timestamp, final long version, final boolean isLatest) {
     172    protected String getInfoText(final Instant timestamp, final long version, final boolean isLatest) {
    173173        String text;
    174174        if (isLatest) {
     
    181181            String date = "?";
    182182            if (timestamp != null) {
    183                 date = DateUtils.formatDateTime(timestamp, DateFormat.SHORT, DateFormat.SHORT);
     183                date = DateUtils.getDateTimeFormatter(FormatStyle.SHORT, FormatStyle.SHORT).format(timestamp);
    184184            }
    185185            text = tr(
     
    226226        if (primitive != null) {
    227227            Changeset cs = primitive.getChangeset();
    228             update(cs, model.isLatest(primitive), primitive.getTimestamp(), primitive.getVersion(), primitive.getPrimitiveId());
     228            update(cs, model.isLatest(primitive), primitive.getInstant(), primitive.getVersion(), primitive.getPrimitiveId());
    229229        }
    230230    }
     
    236236     */
    237237    public void update(final OsmPrimitive primitive, final boolean isLatest) {
    238         Date timestamp = Date.from(primitive.getInstant());
    239         update(Changeset.fromPrimitive(primitive), isLatest, timestamp, primitive.getVersion(), primitive.getPrimitiveId());
     238        update(Changeset.fromPrimitive(primitive), isLatest, primitive.getInstant(), primitive.getVersion(), primitive.getPrimitiveId());
    240239    }
    241240
     
    249248     * @since 14432
    250249     */
    251     public void update(final Changeset cs, final boolean isLatest, final Date timestamp, final long version, final PrimitiveId id) {
     250    public void update(final Changeset cs, final boolean isLatest, final Instant timestamp, final long version, final PrimitiveId id) {
    252251        lblInfo.setText(getInfoText(timestamp, version, isLatest));
    253252        primitiveId = id;
  • trunk/src/org/openstreetmap/josm/gui/history/VersionTableModel.java

    r12620 r17838  
    22package org.openstreetmap.josm.gui.history;
    33
    4 import java.text.DateFormat;
     4import java.time.format.FormatStyle;
    55
    66import javax.swing.table.AbstractTableModel;
     
    5353        case VersionTableColumnModel.COL_DATE:
    5454            HistoryOsmPrimitive p3 = model.getPrimitive(row);
    55             if (p3 != null && p3.getTimestamp() != null)
    56                 return DateUtils.formatDateTime(p3.getTimestamp(), DateFormat.SHORT, DateFormat.SHORT);
     55            if (p3 != null && p3.getInstant() != null)
     56                return DateUtils.getDateTimeFormatter(FormatStyle.SHORT, FormatStyle.SHORT).format(p3.getInstant());
    5757            return null;
    5858        case VersionTableColumnModel.COL_USER:
  • trunk/src/org/openstreetmap/josm/io/AbstractParser.java

    r14946 r17838  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
    6 import java.util.Date;
     6import java.time.Instant;
    77
    88import org.openstreetmap.josm.data.coor.LatLon;
     
    132132
    133133        String v = getMandatoryAttributeString(atts, "timestamp");
    134         Date timestamp = DateUtils.fromString(v);
     134        Instant timestamp = DateUtils.parseInstant(v);
    135135        HistoryOsmPrimitive primitive = null;
    136136        if (type == OsmPrimitiveType.NODE) {
Note: See TracChangeset for help on using the changeset viewer.