- Timestamp:
- 2010-02-03T22:53:24+01:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/PasteAction.java
r2818 r2932 92 92 copy.clearOsmId(); 93 93 if (data instanceof NodeData) { 94 newNodeIds.put(data.get Id(), copy.getId());94 newNodeIds.put(data.getUniqueId(), copy.getUniqueId()); 95 95 } else if (data instanceof WayData) { 96 newWayIds.put(data.get Id(), copy.getId());96 newWayIds.put(data.getUniqueId(), copy.getUniqueId()); 97 97 } else if (data instanceof RelationData) { 98 newRelationIds.put(data.get Id(), copy.getId());98 newRelationIds.put(data.getUniqueId(), copy.getUniqueId()); 99 99 } 100 100 bufferCopy.add(copy); -
trunk/src/org/openstreetmap/josm/command/Command.java
r2844 r2932 1 1 //License: GPL. Copyright 2007 by Immanuel Scholz and others 2 2 package org.openstreetmap.josm.command; 3 4 import static org.openstreetmap.josm.tools.I18n.tr;5 3 6 4 import java.util.Collection; … … 125 123 PrimitiveData to = cloneMap.get(t); 126 124 Main.debug("now: " + t.getId() + " hashCode: " + t.hashCode()); 127 Main.debug("orig: " + to.get Id() + " hashCode: " + to.hashCode());125 Main.debug("orig: " + to.getUniqueId() + " hashCode: " + to.hashCode()); 128 126 } 129 127 return o; -
trunk/src/org/openstreetmap/josm/data/osm/Node.java
r2748 r2932 71 71 72 72 /** 73 * Create new completenode73 * Create new node 74 74 * @param id 75 75 * @param version 76 76 */ 77 77 public Node(long id, int version) { 78 super(id, false); 79 setOsmId(id, version); 78 super(id, version, false); 80 79 } 81 80 -
trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
r2906 r2932 223 223 } 224 224 225 protected OsmPrimitive(PrimitiveData data) { 226 version = data.getVersion(); 227 id = data.getId(); 225 /** 226 * Creates a new primitive for the given id and version. 227 * 228 * If allowNegativeId is set, provided id can be < 0 and will be set to primitive without any processing. 229 * If allowNegativeId is not set, then id will have to be 0 (in that case new unique id will be generated) or 230 * positive number. 231 * 232 * If id is not > 0 version is ignored and set to 0. 233 * 234 * @param id 235 * @param version 236 * @param allowNegativeId 237 * @throws IllegalArgumentException thrown if id < 0 and allowNegativeId is false 238 */ 239 protected OsmPrimitive(long id, int version, boolean allowNegativeId) throws IllegalArgumentException { 240 this(id, allowNegativeId); 241 this.version = (id > 0 ? version : 0); 228 242 } 229 243 … … 1161 1175 public void load(PrimitiveData data) { 1162 1176 setKeys(data.getKeys()); 1163 timestamp = data.getTimestamp();1177 setTimestamp(data.getTimestamp()); 1164 1178 user = data.getUser(); 1165 1179 setChangesetId(data.getChangesetId()); … … 1180 1194 data.getKeys().clear(); 1181 1195 data.getKeys().putAll(getKeys()); 1182 data.setTimestamp( timestamp);1196 data.setTimestamp(getTimestamp()); 1183 1197 data.setUser(user); 1184 1198 data.setDeleted(isDeleted()); -
trunk/src/org/openstreetmap/josm/data/osm/PrimitiveData.java
r2818 r2932 4 4 import java.util.ArrayList; 5 5 import java.util.Collection; 6 import java.util.Date; 6 7 import java.util.HashMap; 7 8 import java.util.List; … … 47 48 private User user; 48 49 private int version; 49 private int timestamp;50 private Date timestamp = new Date(); 50 51 private int changesetId; 51 52 … … 69 70 } 70 71 public long getId() { 71 return id ;72 return id > 0 ? id : 0; 72 73 } 73 74 public void setId(long id) { … … 86 87 this.version = version; 87 88 } 88 public intgetTimestamp() {89 public Date getTimestamp() { 89 90 return timestamp; 90 91 } 91 public void setTimestamp( inttimestamp) {92 public void setTimestamp(Date timestamp) { 92 93 this.timestamp = timestamp; 93 94 } … … 194 195 } 195 196 197 /** 198 * Returns a PrimitiveId object for this primitive 199 * 200 * @return the PrimitiveId for this primitive 201 */ 202 public PrimitiveId getPrimitiveId() { 203 return new SimplePrimitiveId(getUniqueId(), getType()); 204 } 205 196 206 public boolean isNew() { 197 207 return id <= 0; -
trunk/src/org/openstreetmap/josm/data/osm/Relation.java
r2623 r2932 172 172 173 173 /** 174 * Creates new completerelation174 * Creates new relation 175 175 * @param id 176 176 * @param version 177 177 */ 178 178 public Relation(long id, int version) { 179 super(id, false); 180 setOsmId(id, version); 179 super(id, version, false); 181 180 } 182 181 -
trunk/src/org/openstreetmap/josm/data/osm/Way.java
r2741 r2932 183 183 184 184 /** 185 * Creates new way with given id and version. Way is marked as complete185 * Creates new way with given id and version. 186 186 * @param id 187 187 * @param version 188 188 */ 189 189 public Way(long id, int version) { 190 super(id, false); 191 setOsmId(id, version); 190 super(id, version, false); 192 191 } 193 192 -
trunk/src/org/openstreetmap/josm/io/OsmReader.java
r2919 r2932 8 8 import java.util.ArrayList; 9 9 import java.util.Collection; 10 import java.util.Date;11 10 import java.util.HashMap; 12 11 import java.util.LinkedList; … … 24 23 import org.openstreetmap.josm.data.osm.DataSource; 25 24 import org.openstreetmap.josm.data.osm.Node; 25 import org.openstreetmap.josm.data.osm.NodeData; 26 26 import org.openstreetmap.josm.data.osm.OsmPrimitive; 27 27 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 28 import org.openstreetmap.josm.data.osm.PrimitiveData; 28 29 import org.openstreetmap.josm.data.osm.PrimitiveId; 29 30 import org.openstreetmap.josm.data.osm.Relation; 31 import org.openstreetmap.josm.data.osm.RelationData; 30 32 import org.openstreetmap.josm.data.osm.RelationMember; 31 33 import org.openstreetmap.josm.data.osm.SimplePrimitiveId; 32 34 import org.openstreetmap.josm.data.osm.User; 33 35 import org.openstreetmap.josm.data.osm.Way; 36 import org.openstreetmap.josm.data.osm.WayData; 34 37 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 35 38 import org.openstreetmap.josm.gui.progress.ProgressMonitor; … … 66 69 * longs too, but in contrast to internal ids negative values are used 67 70 * to identify primitives unknown to the OSM server 68 *69 * The keys are strings composed as follows70 * <ul>71 * <li>"n" + id for nodes</li>72 * <li>"w" + id for nodes</li>73 * <li>"r" + id for nodes</li>74 * </ul>75 71 */ 76 72 private Map<PrimitiveId, OsmPrimitive> externalIdMap = new HashMap<PrimitiveId, OsmPrimitive>(); … … 86 82 } 87 83 88 private static class OsmPrimitiveData {89 public long id = 0;90 public boolean modified = false;91 public boolean deleted = false;92 public Date timestamp = new Date();93 public User user = null;94 public boolean visible = true;95 public int version = 0;96 public LatLon latlon = new LatLon(0,0);97 private OsmPrimitive primitive;98 private int changesetId;99 100 public void copyTo(OsmPrimitive osm) {101 // It's not necessary to call clearOsmId for id < 0. The same thing is done by parameterless constructor102 if (id > 0) {103 osm.setOsmId(id, version);104 }105 osm.setDeleted(deleted);106 osm.setModified(modified | deleted);107 osm.setTimestamp(timestamp);108 osm.setUser(user);109 if (!osm.isNew() && changesetId > 0) {110 osm.setChangesetId(changesetId);111 } else if (osm.isNew() && changesetId > 0) {112 System.out.println(tr("Warning: ignoring changeset id {0} for new object with external id {1} and internal id {2}",113 changesetId,114 id,115 osm.getUniqueId()116 ));117 }118 if (! osm.isNew()) {119 // ignore visible attribute for objects not yet known to the server120 //121 osm.setVisible(visible);122 }123 osm.mappaintStyle = null;124 }125 126 public Node createNode() {127 Node node = new Node();128 node.setCoor(latlon);129 copyTo(node);130 primitive = node;131 return node;132 }133 134 public Way createWay() {135 Way way = new Way();136 copyTo(way);137 primitive = way;138 return way;139 }140 public Relation createRelation() {141 Relation relation= new Relation();142 copyTo(relation);143 primitive = relation;144 return relation;145 }146 147 public void rememberTag(String key, String value) {148 primitive.put(key, value);149 }150 }151 152 84 /** 153 85 * Used as a temporary storage for relation members, before they … … 155 87 */ 156 88 private static class RelationMemberData { 157 public Stringtype;89 public OsmPrimitiveType type; 158 90 public long id; 159 91 public String role; … … 184 116 * The current osm primitive to be read. 185 117 */ 186 private OsmPrimitiveData current; 118 private OsmPrimitive currentPrimitive; 119 private long currentExternalId; 187 120 private String generator; 188 121 … … 229 162 230 163 } else if (qName.equals("node")) { 231 current = new OsmPrimitiveData(); 232 current.latlon = new LatLon(getDouble(atts, "lat"), getDouble(atts, "lon")); 233 readCommon(atts, current); 234 Node n = current.createNode(); 235 externalIdMap.put(new SimplePrimitiveId(current.id, OsmPrimitiveType.NODE), n); 164 NodeData nd = new NodeData(); 165 nd.setCoor(new LatLon(getDouble(atts, "lat"), getDouble(atts, "lon"))); 166 readCommon(atts, nd); 167 Node n = new Node(nd.getId(), nd.getVersion()); 168 n.load(nd); 169 externalIdMap.put(nd.getPrimitiveId(), n); 170 currentPrimitive = n; 171 currentExternalId = nd.getUniqueId(); 236 172 } else if (qName.equals("way")) { 237 current = new OsmPrimitiveData(); 238 readCommon(atts, current); 239 Way w = current.createWay(); 240 externalIdMap.put(new SimplePrimitiveId(current.id, OsmPrimitiveType.WAY), w); 241 ways.put(current.id, new ArrayList<Long>()); 173 WayData wd = new WayData(); 174 readCommon(atts, wd); 175 Way w = new Way(wd.getId(), wd.getVersion()); 176 w.load(wd); 177 externalIdMap.put(wd.getPrimitiveId(), w); 178 ways.put(wd.getUniqueId(), new ArrayList<Long>()); 179 currentPrimitive = w; 180 currentExternalId = wd.getUniqueId(); 242 181 } else if (qName.equals("nd")) { 243 Collection<Long> list = ways.get(current .id);182 Collection<Long> list = ways.get(currentExternalId); 244 183 if (list == null) { 245 184 throwException( … … 249 188 if (atts.getValue("ref") == null) { 250 189 throwException( 251 tr("Missing mandatory attribute ''{0}'' on <nd> of way {1}.", "ref", current .id)190 tr("Missing mandatory attribute ''{0}'' on <nd> of way {1}.", "ref", currentPrimitive.getUniqueId()) 252 191 ); 253 192 } … … 258 197 ); 259 198 } 260 if (current .deleted) {261 logger.info(tr("Deleted way {0} contains nodes", current .id));199 if (currentPrimitive.isDeleted()) { 200 logger.info(tr("Deleted way {0} contains nodes", currentPrimitive.getUniqueId())); 262 201 } else { 263 202 list.add(id); … … 267 206 268 207 } else if (qName.equals("relation")) { 269 current = new OsmPrimitiveData(); 270 readCommon(atts, current); 271 Relation r = current.createRelation(); 272 externalIdMap.put(new SimplePrimitiveId(current.id, OsmPrimitiveType.RELATION), r); 273 relations.put(current.id, new LinkedList<RelationMemberData>()); 208 RelationData rd = new RelationData(); 209 readCommon(atts, rd); 210 Relation r = new Relation(rd.getId(), rd.getVersion()); 211 r.load(rd); 212 externalIdMap.put(rd.getPrimitiveId(), r); 213 relations.put(r.getUniqueId(), new LinkedList<RelationMemberData>()); 214 currentPrimitive = r; 215 currentExternalId = rd.getUniqueId(); 274 216 } else if (qName.equals("member")) { 275 Collection<RelationMemberData> list = relations.get(current .id);217 Collection<RelationMemberData> list = relations.get(currentExternalId); 276 218 if (list == null) { 277 219 throwException( … … 282 224 String value = atts.getValue("ref"); 283 225 if (value == null) { 284 throwException(tr("Missing attribute ''ref'' on member in relation {0}.",current .id));226 throwException(tr("Missing attribute ''ref'' on member in relation {0}.",currentPrimitive.getUniqueId())); 285 227 } 286 228 try { 287 229 emd.id = Long.parseLong(value); 288 230 } catch(NumberFormatException e) { 289 throwException(tr("Illegal value for attribute ''ref'' on member in relation {0}. Got {1}", Long.toString(current .id),value));231 throwException(tr("Illegal value for attribute ''ref'' on member in relation {0}. Got {1}", Long.toString(currentPrimitive.getUniqueId()),value)); 290 232 } 291 233 value = atts.getValue("type"); 292 234 if (value == null) { 293 throwException(tr("Missing attribute ''type'' on member {0} in relation {1}.", Long.toString(emd.id), Long.toString(current.id))); 294 } 295 if (! (value.equals("way") || value.equals("node") || value.equals("relation"))) { 296 throwException(tr("Illegal value for attribute ''type'' on member {0} in relation {1}. Got {2}.", Long.toString(emd.id), Long.toString(current.id), value)); 297 } 298 emd.type= value; 235 throwException(tr("Missing attribute ''type'' on member {0} in relation {1}.", Long.toString(emd.id), Long.toString(currentPrimitive.getUniqueId()))); 236 } 237 try { 238 emd.type = OsmPrimitiveType.fromApiTypeName(value); 239 } catch(IllegalArgumentException e) { 240 throwException(tr("Illegal value for attribute ''type'' on member {0} in relation {1}. Got {2}.", Long.toString(emd.id), Long.toString(currentPrimitive.getUniqueId()), value)); 241 } 299 242 value = atts.getValue("role"); 300 243 emd.role = value; … … 304 247 } 305 248 306 if (current .deleted) {307 logger.info(tr("Deleted relation {0} contains members", current .id));249 if (currentPrimitive.isDeleted()) { 250 logger.info(tr("Deleted relation {0} contains members", currentPrimitive.getUniqueId())); 308 251 } else { 309 252 list.add(emd); … … 315 258 String key = atts.getValue("k"); 316 259 String value = atts.getValue("v"); 317 current .rememberTag(key, value);260 currentPrimitive.put(key, value); 318 261 } else { 319 262 System.out.println(tr("Undefined element ''{0}'' found in input stream. Skipping.", qName)); … … 342 285 * Read out the common attributes from atts and put them into this.current. 343 286 */ 344 void readCommon(Attributes atts, OsmPrimitiveData current) throws SAXException {345 current. id = getLong(atts, "id");346 if (current. id== 0) {287 void readCommon(Attributes atts, PrimitiveData current) throws SAXException { 288 current.setId(getLong(atts, "id")); 289 if (current.getUniqueId() == 0) { 347 290 throwException(tr("Illegal object with ID=0.")); 348 291 } … … 350 293 String time = atts.getValue("timestamp"); 351 294 if (time != null && time.length() != 0) { 352 current. timestamp = DateUtils.fromString(time);295 current.setTimestamp(DateUtils.fromString(time)); 353 296 } 354 297 … … 357 300 // uid attribute added in 0.6 API 358 301 String uid = atts.getValue("uid"); 359 current. user = createUser(uid, user);302 current.setUser(createUser(uid, user)); 360 303 361 304 // visible attribute added in 0.4 API 362 305 String visible = atts.getValue("visible"); 363 306 if (visible != null) { 364 current. visible = Boolean.parseBoolean(visible);365 } 366 367 String version = atts.getValue("version");368 current.version = 0;369 if (version != null) {307 current.setVisible(Boolean.parseBoolean(visible)); 308 } 309 310 String versionString = atts.getValue("version"); 311 int version = 0; 312 if (versionString != null) { 370 313 try { 371 current.version = Integer.parseInt(version);314 version = Integer.parseInt(versionString); 372 315 } catch(NumberFormatException e) { 373 throwException(tr("Illegal value for attribute ''version'' on OSM primitive with ID {0}. Got {1}.", Long.toString(current. id), version));316 throwException(tr("Illegal value for attribute ''version'' on OSM primitive with ID {0}. Got {1}.", Long.toString(current.getUniqueId()), versionString)); 374 317 } 375 318 if (ds.getVersion().equals("0.6")){ 376 if ( current.version <= 0 && current.id> 0) {377 throwException(tr("Illegal value for attribute ''version'' on OSM primitive with ID {0}. Got {1}.", Long.toString(current. id), version));378 } else if ( current.version < 0 && current.id <=0) {379 System.out.println(tr("WARNING: Normalizing value of attribute ''version'' of element {0} to {2}, API version is ''{3}''. Got {1}.", current. id, current.version, 0, "0.6"));380 current.version = 0;319 if (version <= 0 && current.getUniqueId() > 0) { 320 throwException(tr("Illegal value for attribute ''version'' on OSM primitive with ID {0}. Got {1}.", Long.toString(current.getUniqueId()), versionString)); 321 } else if (version < 0 && current.getUniqueId() <= 0) { 322 System.out.println(tr("WARNING: Normalizing value of attribute ''version'' of element {0} to {2}, API version is ''{3}''. Got {1}.", current.getUniqueId(), version, 0, "0.6")); 323 version = 0; 381 324 } 382 325 } else if (ds.getVersion().equals("0.5")) { 383 if ( current.version <= 0 && current.id> 0) {384 System.out.println(tr("WARNING: Normalizing value of attribute ''version'' of element {0} to {2}, API version is ''{3}''. Got {1}.", current. id, current.version, 1, "0.5"));385 current.version = 1;386 } else if ( current.version < 0 && current.id <=0) {387 System.out.println(tr("WARNING: Normalizing value of attribute ''version'' of element {0} to {2}, API version is ''{3}''. Got {1}.", current. id, current.version, 0, "0.5"));388 current.version = 0;326 if (version <= 0 && current.getUniqueId() > 0) { 327 System.out.println(tr("WARNING: Normalizing value of attribute ''version'' of element {0} to {2}, API version is ''{3}''. Got {1}.", current.getUniqueId(), version, 1, "0.5")); 328 version = 1; 329 } else if (version < 0 && current.getUniqueId() <= 0) { 330 System.out.println(tr("WARNING: Normalizing value of attribute ''version'' of element {0} to {2}, API version is ''{3}''. Got {1}.", current.getUniqueId(), version, 0, "0.5")); 331 version = 0; 389 332 } 390 333 } else { … … 395 338 // version expected for OSM primitives with an id assigned by the server (id > 0), since API 0.6 396 339 // 397 if (current. id> 0 && ds.getVersion() != null && ds.getVersion().equals("0.6")) {398 throwException(tr("Missing attribute ''version'' on OSM primitive with ID {0}.", Long.toString(current. id)));399 } else if (current. id> 0 && ds.getVersion() != null && ds.getVersion().equals("0.5")) {340 if (current.getUniqueId() > 0 && ds.getVersion() != null && ds.getVersion().equals("0.6")) { 341 throwException(tr("Missing attribute ''version'' on OSM primitive with ID {0}.", Long.toString(current.getUniqueId()))); 342 } else if (current.getUniqueId() > 0 && ds.getVersion() != null && ds.getVersion().equals("0.5")) { 400 343 // default version in 0.5 files for existing primitives 401 System.out.println(tr("WARNING: Normalizing value of attribute ''version'' of element {0} to {2}, API version is ''{3}''. Got {1}.", current. id, current.version, 1, "0.5"));402 current.version= 1;403 } else if (current. id<= 0 && ds.getVersion() != null && ds.getVersion().equals("0.5")) {344 System.out.println(tr("WARNING: Normalizing value of attribute ''version'' of element {0} to {2}, API version is ''{3}''. Got {1}.", current.getUniqueId(), version, 1, "0.5")); 345 version= 1; 346 } else if (current.getUniqueId() <= 0 && ds.getVersion() != null && ds.getVersion().equals("0.5")) { 404 347 // default version in 0.5 files for new primitives, no warning necessary. This is 405 348 // (was) legal in API 0.5 406 current.version= 0; 407 } 408 } 349 version= 0; 350 } 351 } 352 current.setVersion(version); 409 353 410 354 String action = atts.getValue("action"); … … 412 356 // do nothing 413 357 } else if (action.equals("delete")) { 414 current. deleted = true;358 current.setDeleted(true); 415 359 } else if (action.startsWith("modify")) { //FIXME: why startsWith()? why not equals()? 416 current. modified = true;360 current.setModified(true); 417 361 } 418 362 419 363 String v = atts.getValue("changeset"); 420 364 if (v == null) { 421 current. changesetId = 0;365 current.setChangesetId(0); 422 366 } else { 423 367 try { 424 current. changesetId = Integer.parseInt(v);368 current.setChangesetId(Integer.parseInt(v)); 425 369 } catch(NumberFormatException e) { 426 if (current. id<= 0) {370 if (current.getUniqueId() <= 0) { 427 371 // for a new primitive we just log a warning 428 System.out.println(tr("Illegal value for attribute ''changeset'' on new object {1}. Got {0}. Resetting to 0.", v, current. id));429 current. changesetId = 0;372 System.out.println(tr("Illegal value for attribute ''changeset'' on new object {1}. Got {0}. Resetting to 0.", v, current.getUniqueId())); 373 current.setChangesetId(0); 430 374 } else { 431 375 // for an existing primitive this is a problem … … 433 377 } 434 378 } 435 if (current. changesetId<=0) {436 if (current. id<= 0) {379 if (current.getChangesetId() <=0) { 380 if (current.getUniqueId() <= 0) { 437 381 // for a new primitive we just log a warning 438 System.out.println(tr("Illegal value for attribute ''changeset'' on new object {1}. Got {0}. Resetting to 0.", v, current. id));439 current. changesetId = 0;382 System.out.println(tr("Illegal value for attribute ''changeset'' on new object {1}. Got {0}. Resetting to 0.", v, current.getUniqueId())); 383 current.setChangesetId(0); 440 384 } else { 441 385 // for an existing primitive this is a problem … … 475 419 if (id <= 0) 476 420 throw new IllegalDataException ( 477 tr( 478 "Way with external ID ''{0}'' includes missing node with external ID ''{1}''.", 421 tr("Way with external ID ''{0}'' includes missing node with external ID ''{1}''.", 479 422 externalWayId, 480 id 481 ) 482 ); 423 id)); 483 424 // create an incomplete node if necessary 484 425 // … … 490 431 } 491 432 if (n.isDeleted()) { 492 logger.warning(tr("Deleted node {0} was removed from way {1}", id, w.getId())); 493 } else { 494 wayNodes.add(n); 495 } 433 logger.warning(tr("Deleted node {0} is part of way {1}", id, w.getId())); 434 } 435 wayNodes.add(n); 496 436 } 497 437 w.setNodes(wayNodes); 498 438 if (w.hasIncompleteNodes()) { 499 439 if (logger.isLoggable(Level.FINE)) { 500 logger.fine(tr("Marked way {0} with {1} nodes incomplete because at least one node was missing in the " + 501 "loaded data and is therefore incomplete too.", externalWayId, w.getNodesCount())); 502 } 503 ds.addPrimitive(w); 504 } else { 505 ds.addPrimitive(w); 506 } 440 logger.fine(tr("Way {0} with {1} nodes has incomplete nodes because at least one node was missing in the loaded data.", 441 externalWayId, w.getNodesCount())); 442 } 443 } 444 ds.addPrimitive(w); 507 445 } 508 446 } … … 538 476 539 477 // lookup the member from the map of already created primitives 540 // 541 try { 542 OsmPrimitiveType type = OsmPrimitiveType.fromApiTypeName(rm.type); 543 primitive = externalIdMap.get(new SimplePrimitiveId(rm.id, type)); 544 } catch(IllegalArgumentException e) { 545 throw new IllegalDataException( 546 tr("Unknown relation member type ''{0}'' in relation with external id ''{1}''.", rm.type,externalRelationId) 547 ); 548 } 478 primitive = externalIdMap.get(new SimplePrimitiveId(rm.id, rm.type)); 549 479 550 480 if (primitive == null) { … … 555 485 // 556 486 throw new IllegalDataException( 557 tr( 558 "Relation with external id ''{0}'' refers to a missing primitive with external id ''{1}''.", 487 tr("Relation with external id ''{0}'' refers to a missing primitive with external id ''{1}''.", 559 488 externalRelationId, 560 rm.id 561 ) 562 ); 489 rm.id)); 563 490 564 491 // member refers to OSM primitive which was not present in the parsed data 565 492 // -> create a new incomplete primitive and add it to the dataset 566 493 // 567 if (rm.type.equals("node")) { 568 primitive = new Node(rm.id); 569 } else if (rm.type.equals("way")) { 570 primitive = new Way(rm.id); 571 } else if (rm.type.equals("relation")) { 572 primitive = new Relation(rm.id); 573 } else 574 // can't happen, we've been testing for valid member types 575 // at the beginning of this method 576 // 577 throw new AssertionError(); 578 ds.addPrimitive(primitive); 579 externalIdMap.put(new SimplePrimitiveId(rm.id, OsmPrimitiveType.fromApiTypeName(rm.type)), primitive); 494 primitive = ds.getPrimitiveById(rm.id, rm.type); 495 if (primitive == null) { 496 switch (rm.type) { 497 case NODE: 498 primitive = new Node(rm.id); break; 499 case WAY: 500 primitive = new Way(rm.id); break; 501 case RELATION: 502 primitive = new Relation(rm.id); break; 503 default: throw new AssertionError(); // can't happen 504 } 505 506 ds.addPrimitive(primitive); 507 externalIdMap.put(new SimplePrimitiveId(rm.id, rm.type), primitive); 508 } 580 509 } 581 510 if (primitive.isDeleted()) { 582 logger.warning(tr("Deleted member {0} was removed from relation {1}", primitive.getId(), relation.getId())); 583 } else { 584 relationMembers.add(new RelationMember(rm.role, primitive)); 585 } 511 logger.warning(tr("Deleted member {0} is used by relation {1}", primitive.getId(), relation.getId())); 512 } 513 relationMembers.add(new RelationMember(rm.role, primitive)); 586 514 } 587 515 relation.setMembers(relationMembers);
Note:
See TracChangeset
for help on using the changeset viewer.