Changeset 17749 in josm for trunk/src/org
- Timestamp:
- 2021-04-11T21:56:50+02:00 (4 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmChangeTask.java
r16453 r17749 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.time.Instant; 6 7 import java.util.Arrays; 7 8 import java.util.Date; … … 112 113 // A changeset does not contain all referred primitives, this is the map of incomplete ones 113 114 // 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<>(); 115 116 for (OsmPrimitive p : downloadedData.allNonDeletedPrimitives()) { 116 117 if (p.isIncomplete()) { 117 Datetimestamp = p.getReferrers().stream()118 Instant timestamp = p.getReferrers().stream() 118 119 .filter(ref -> !ref.isTimestampEmpty()) 119 120 .findFirst() 120 .map(AbstractPrimitive::get Timestamp)121 .map(AbstractPrimitive::getInstant) 121 122 .orElse(null); 122 123 toLoad.put(p, timestamp); … … 138 139 private static final class HistoryLoaderAndListener extends HistoryLoadTask implements HistoryDataSetListener { 139 140 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) { 143 144 this.toLoad = toLoad; 144 145 this.setChangesetDataNeeded(false); … … 150 151 @Override 151 152 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(); 155 156 OsmPrimitive p = entry.getKey(); 156 157 History history = source.getHistory(p.getPrimitiveId()); 157 Datedate = entry.getValue();158 Instant date = entry.getValue(); 158 159 // If the history has been loaded and a timestamp is known 159 160 if (history != null && date != null) { 160 161 // Lookup for the primitive version at the specified timestamp 161 HistoryOsmPrimitive hp = history.getByDate( date);162 HistoryOsmPrimitive hp = history.getByDate(Date.from(date)); 162 163 if (hp != null) { 163 164 PrimitiveData data; -
trunk/src/org/openstreetmap/josm/data/osm/AbstractPrimitive.java
r17589 r17749 5 5 6 6 import java.text.MessageFormat; 7 import java.time.Instant; 7 8 import java.util.Arrays; 8 9 import java.util.Collection; … … 297 298 } 298 299 300 @Deprecated 299 301 @Override 300 302 public void setTimestamp(Date timestamp) { … … 303 305 304 306 @Override 307 public void setInstant(Instant timestamp) { 308 this.timestamp = (int) timestamp.getEpochSecond(); 309 } 310 311 @Override 305 312 public void setRawTimestamp(int timestamp) { 306 313 this.timestamp = timestamp; 307 314 } 308 315 316 @Deprecated 309 317 @Override 310 318 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)); 312 325 } 313 326 -
trunk/src/org/openstreetmap/josm/data/osm/Changeset.java
r17717 r17749 103 103 final Changeset changeset = new Changeset(primitive.getChangesetId()); 104 104 changeset.setUser(primitive.getUser()); 105 changeset.setCreatedAt(primitive.get Timestamp().toInstant()); // not accurate in all cases105 changeset.setCreatedAt(primitive.getInstant()); // not accurate in all cases 106 106 return changeset; 107 107 } -
trunk/src/org/openstreetmap/josm/data/osm/IPrimitive.java
r17459 r17749 2 2 package org.openstreetmap.josm.data.osm; 3 3 4 import java.time.Instant; 4 5 import java.util.Date; 5 6 import java.util.List; … … 276 277 * @return date of last modification 277 278 * @see #setTimestamp 278 */ 279 * @deprecated Use {@link #getInstant} 280 */ 281 @Deprecated 279 282 Date getTimestamp(); 280 283 … … 284 287 * used to check against edit conflicts. 285 288 * 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 * 286 299 * @return last modification as timestamp 287 300 * @see #setRawTimestamp … … 293 306 * @param timestamp date of last modification 294 307 * @see #getTimestamp 295 */ 308 * @deprecated Use {@link #setInstant} 309 */ 310 @Deprecated 296 311 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); 297 319 298 320 /** -
trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
r17584 r17749 301 301 } 302 302 303 @Deprecated 303 304 @Override 304 305 public void setTimestamp(Date timestamp) { -
trunk/src/org/openstreetmap/josm/data/osm/history/HistoryOsmPrimitive.java
r16913 r17749 96 96 */ 97 97 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())); 99 99 } 100 100 … … 364 364 Logging.log(Logging.LEVEL_ERROR, "Cannot change visibility for "+data+':', e); 365 365 } 366 data.set Timestamp(timestamp);366 data.setInstant(timestamp.toInstant()); 367 367 data.setKeys(tags); 368 368 data.setOsmId(id, (int) version); -
trunk/src/org/openstreetmap/josm/data/osm/search/SearchCompiler.java
r17747 r17749 741 741 String mv; 742 742 if ("timestamp".equals(key) && osm instanceof OsmPrimitive) { 743 mv = DateUtils.fromTimestamp(((OsmPrimitive) osm).getRawTimestamp());743 mv = ((OsmPrimitive) osm).getInstant().toString(); 744 744 } else { 745 745 mv = osm.get(key); … … 1493 1493 try { 1494 1494 // 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(); 1496 1496 } catch (UncheckedParseException | DateTimeException ex) { 1497 1497 throw new SearchParseError(tr("Cannot parse timestamp ''{0}''", rangeA1), ex); … … 1499 1499 try { 1500 1500 // 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(); 1502 1502 } catch (UncheckedParseException | DateTimeException ex) { 1503 1503 throw new SearchParseError(tr("Cannot parse timestamp ''{0}''", rangeA2), ex); … … 1508 1508 @Override 1509 1509 protected Long getNumber(OsmPrimitive osm) { 1510 return osm.get Timestamp().getTime();1510 return osm.getInstant().toEpochMilli(); 1511 1511 } 1512 1512 -
trunk/src/org/openstreetmap/josm/gui/dialogs/InspectPrimitiveDataText.java
r17585 r17749 154 154 add(tr("Data Set: "), Integer.toHexString(o.getDataSet().hashCode())); 155 155 add(tr("Edited at: "), o.isTimestampEmpty() ? tr("<new object>") 156 : DateUtils.fromTimestamp(o.getRawTimestamp()));156 : o.getInstant().toString()); 157 157 add(tr("Edited by: "), o.getUser() == null ? tr("<new object>") 158 158 : getNameAndId(o.getUser().getName(), o.getUser().getId())); -
trunk/src/org/openstreetmap/josm/gui/history/VersionInfoPanel.java
r14463 r17749 236 236 */ 237 237 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()); 239 240 } 240 241 -
trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r17715 r17749 24 24 import java.io.IOException; 25 25 import java.time.DateTimeException; 26 import java.time.Instant;27 26 import java.util.ArrayList; 28 27 import java.util.Arrays; … … 877 876 wpt.setTimeInMillis(time); 878 877 } else if ((v = gpxVal(n, GpxConstants.PT_TIME)) != null) { 879 wpt.set TimeInMillis(DateUtils.tsFromString(v));878 wpt.setInstant(DateUtils.parseInstant(v)); 880 879 } else if (!n.isTimestampEmpty()) { 881 wpt.setInstant(Instant .ofEpochSecond(Integer.toUnsignedLong(n.getRawTimestamp())));880 wpt.setInstant(n.getInstant()); 882 881 } 883 882 } catch (UncheckedParseException | DateTimeException e) { -
trunk/src/org/openstreetmap/josm/gui/layer/gpx/ConvertFromGpxLayerAction.java
r17715 r17749 9 9 import java.time.Instant; 10 10 import java.util.ArrayList; 11 import java.util.Date;12 11 import java.util.List; 13 12 import java.util.Map; … … 135 134 p.put(GpxConstants.GPX_PREFIX + key, String.valueOf(date)); 136 135 } 137 p.set Timestamp(Date.from(date));136 p.setInstant(date); 138 137 } 139 138 } -
trunk/src/org/openstreetmap/josm/io/AbstractReader.java
r17166 r17749 431 431 } 432 432 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())); 434 434 current.setRawTimestamp(timestamp); 435 435 } catch (UncheckedParseException | DateTimeException e) { -
trunk/src/org/openstreetmap/josm/io/DiffResultProcessor.java
r17717 r17749 9 9 import java.util.Collection; 10 10 import java.util.Collections; 11 import java.util.Date;12 11 import java.util.HashMap; 13 12 import java.util.HashSet; … … 153 152 // TODO is there a way to obtain the timestamp for non-closed changesets? 154 153 Instant instant = Utils.firstNonNull(cs.getClosedAt(), Instant.now()); 155 p.set Timestamp(Date.from(instant));154 p.setInstant(instant); 156 155 } 157 156 } -
trunk/src/org/openstreetmap/josm/io/OsmWriter.java
r17717 r17749 366 366 } 367 367 if (!osm.isTimestampEmpty()) { 368 out.print(" timestamp='"+ DateUtils.fromTimestamp(osm.getRawTimestamp())+'\'');368 out.print(" timestamp='"+osm.getInstant()+'\''); 369 369 } 370 370 // user and visible added with 0.4 API
Note:
See TracChangeset
for help on using the changeset viewer.