Changeset 17749 in josm
- Timestamp:
- 2021-04-11T21:56:50+02:00 (4 years ago)
- Location:
- trunk
- Files:
-
- 18 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 -
trunk/test/unit/org/openstreetmap/josm/data/osm/DataSetMergerTest.java
r17346 r17749 14 14 import java.time.Instant; 15 15 import java.util.Arrays; 16 import java.util.Date;17 16 18 17 import org.junit.jupiter.api.AfterEach; … … 25 24 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 26 25 import org.openstreetmap.josm.testutils.JOSMTestRules; 27 import org.openstreetmap.josm.tools.date.DateUtils;28 26 29 27 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; … … 307 305 n.put("key1", "value1"); 308 306 n.setUser(myUser); 309 n.set Timestamp(new Date());307 n.setInstant(Instant.now()); 310 308 311 309 my.addPrimitive(n); … … 314 312 n1.setCoor(LatLon.ZERO); 315 313 n1.put("key1", "value1"); 316 n1.set Timestamp(Date.from(Instant.now().plusSeconds(3600)));314 n1.setInstant(Instant.now().plusSeconds(3600)); 317 315 n1.setUser(theirUser); 318 316 their.addPrimitive(n1); … … 346 344 n1.setOsmId(1, 1); 347 345 n1.put("key1", "value1"); 348 n1.set Timestamp(new Date());346 n1.setInstant(Instant.now()); 349 347 their.addPrimitive(n1); 350 348 … … 646 644 User user = User.createOsmUser(1111, "their"); 647 645 theirWay.setUser(user); 648 theirWay.set Timestamp(new Date());646 theirWay.setInstant(Instant.now()); 649 647 their.addPrimitive(theirWay); 650 648 … … 699 697 User user = User.createOsmUser(1111, "their"); 700 698 theirWay.setUser(user); 701 theirWay.set Timestamp(new Date());699 theirWay.setInstant(Instant.now()); 702 700 their.addPrimitive(theirWay); 703 701 … … 754 752 theirWay.addNode(tn3); 755 753 theirWay.setUser(User.createOsmUser(1111, "their")); 756 theirWay.set Timestamp(new Date());754 theirWay.setInstant(Instant.now()); 757 755 their.addPrimitive(theirWay); 758 756 … … 1182 1180 Node nA = new Node(2848219691L, 1); 1183 1181 nA.setCoor(LatLon.ZERO); 1184 nA.set Timestamp(DateUtils.fromString("2014-05-10T14:25:40Z"));1182 nA.setInstant(Instant.parse("2014-05-10T14:25:40Z")); 1185 1183 nA.setChangesetId(22251108); 1186 1184 nA.setUser(User.createOsmUser(385987, "yaho")); -
trunk/test/unit/org/openstreetmap/josm/data/osm/search/SearchCompilerTest.java
r17746 r17749 13 13 import java.nio.file.Files; 14 14 import java.nio.file.Paths; 15 import java.time.Instant; 15 16 import java.util.Arrays; 16 17 import java.util.Collection; … … 44 45 import org.openstreetmap.josm.testutils.JOSMTestRules; 45 46 import org.openstreetmap.josm.tools.Logging; 46 import org.openstreetmap.josm.tools.date.DateUtils;47 47 48 48 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; … … 449 449 void testTimestamp() throws SearchParseError { 450 450 final Node n1 = new Node(); 451 n1.set Timestamp(DateUtils.fromString("2010-01-22"));451 n1.setInstant(Instant.parse("2010-01-22T00:00:00Z")); 452 452 assertTrue(SearchCompiler.compile("timestamp:2010/2011").match(n1)); 453 453 assertTrue(SearchCompiler.compile("timestamp:2010-01/2011").match(n1)); … … 455 455 assertFalse(SearchCompiler.compile("timestamp:2010-01-23/2011").match(n1)); 456 456 assertFalse(SearchCompiler.compile("timestamp:2010/2010-01-21").match(n1)); 457 n1.set Timestamp(DateUtils.fromString("2016-01-22"));457 n1.setInstant(Instant.parse("2016-01-22T00:00:00Z")); 458 458 assertFalse(SearchCompiler.compile("timestamp:2010/2011").match(n1)); 459 459 } -
trunk/test/unit/org/openstreetmap/josm/io/OsmJsonReaderTest.java
r17275 r17749 9 9 import java.io.InputStream; 10 10 import java.nio.charset.StandardCharsets; 11 import java.time.Instant; 11 12 import java.util.Iterator; 12 13 … … 131 132 assertEquals(1, n.getUniqueId()); 132 133 assertEquals(new LatLon(2.0, -3.0), n.getCoor()); 133 assertEquals( "2018-01-01T00:00:00Z", DateUtils.newIsoDateTimeFormat().format(n.getTimestamp()));134 assertEquals(Instant.parse("2018-01-01T00:00:00Z"), n.getInstant()); 134 135 assertEquals(4, n.getVersion()); 135 136 assertEquals(5, n.getChangesetId()); -
trunk/test/unit/org/openstreetmap/josm/io/OsmWriterTest.java
r17717 r17749 24 24 import org.openstreetmap.josm.data.osm.DataSet; 25 25 import org.openstreetmap.josm.data.osm.DownloadPolicy; 26 import org.openstreetmap.josm.data.osm.INode; 27 import org.openstreetmap.josm.data.osm.Node; 26 28 import org.openstreetmap.josm.data.osm.NodeData; 27 29 import org.openstreetmap.josm.data.osm.UploadPolicy; … … 127 129 } 128 130 } 131 132 /** 133 * Unit test of {@link OsmWriter#visit(INode)}. 134 * @throws IOException if an I/O error occurs 135 */ 136 @Test 137 void testNode() throws IOException { 138 Node node = new Node(1, 42); 139 node.setCoor(new LatLon(12., 34.)); 140 node.setInstant(Instant.parse("2006-05-10T18:27:47Z")); 141 try (StringWriter stringWriter = new StringWriter(); 142 OsmWriter osmWriter = OsmWriterFactory.createOsmWriter(new PrintWriter(stringWriter), true, OsmWriter.DEFAULT_API_VERSION)) { 143 osmWriter.visit(node); 144 assertEquals(" <node id='1' timestamp='2006-05-10T18:27:47Z' visible='true' version='42' lat='12.0' lon='34.0' />\n", 145 stringWriter.toString().replace("\r", "")); 146 } 147 } 129 148 }
Note:
See TracChangeset
for help on using the changeset viewer.