Changeset 366 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2007-10-11T23:28:26+02:00 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/visitor/MergeVisitor.java
r362 r366 26 26 /** 27 27 * Map from primitives in the database to visited primitives. (Attention: The other way 28 * round than merged Nodes)28 * round than mergedPrims) 29 29 */ 30 30 public Map<OsmPrimitive, OsmPrimitive> conflicts = new HashMap<OsmPrimitive, OsmPrimitive>(); … … 38 38 * in ds.nodes instead. 39 39 */ 40 private final Map<Node, Node> mergedNodes = new HashMap<Node, Node>(); 40 private final Map<OsmPrimitive, OsmPrimitive> mergedPrims 41 = new HashMap<OsmPrimitive, OsmPrimitive>(); 41 42 42 43 public MergeVisitor(DataSet ds, DataSet mergeds) { … … 50 51 */ 51 52 public void visit(Node other) { 52 if (mergeAfterId(merged Nodes, ds.nodes, other))53 if (mergeAfterId(mergedPrims, ds.nodes, other)) 53 54 return; 54 55 … … 63 64 ds.nodes.add(other); 64 65 else { 65 merged Nodes.put(other, my);66 mergedPrims.put(other, my); 66 67 mergeCommon(my, other); 67 68 if (my.modified && !other.modified) … … 75 76 } 76 77 77 /**78 * Simply calls cloneFrom() for now.79 * Might be useful to keep around to facilitate merge with the relations80 * branch.81 */82 78 private <T extends OsmPrimitive> void cloneFromExceptIncomplete(T myOsm, T otherOsm) { 83 myOsm.cloneFrom(otherOsm); 79 if (!otherOsm.incomplete) { 80 myOsm.cloneFrom(otherOsm); 81 } 84 82 } 85 83 … … 89 87 */ 90 88 public void visit(Way other) { 91 if (mergeAfterId( null, ds.ways, other))89 if (mergeAfterId(mergedPrims, ds.ways, other)) 92 90 return; 93 91 … … 102 100 ds.ways.add(other); 103 101 } else { 102 mergedPrims.put(other, my); 104 103 mergeCommon(my, other); 105 104 if (my.modified && !other.modified) … … 151 150 }*/ 152 151 } else { 152 mergedPrims.put(other, my); 153 153 mergeCommon(my, other); 154 154 if (my.modified && !other.modified) … … 191 191 */ 192 192 public void fixReferences() { 193 for (Way w : ds.ways) 194 fixWay(w);193 for (Way w : ds.ways) fixWay(w); 194 for (Relation r : ds.relations) fixRelation(r); 195 195 for (OsmPrimitive osm : conflicts.values()) 196 196 if (osm instanceof Way) 197 197 fixWay((Way)osm); 198 else if (osm instanceof Relation) 199 fixRelation((Relation) osm); 198 200 } 199 201 … … 202 204 LinkedList<Node> newNodes = new LinkedList<Node>(); 203 205 for (Node n : w.nodes) { 204 Node otherN = mergedNodes.get(n);206 Node otherN = (Node) mergedPrims.get(n); 205 207 newNodes.add(otherN == null ? n : otherN); 206 208 if (otherN != null) … … 210 212 w.nodes.clear(); 211 213 w.nodes.addAll(newNodes); 214 } 212 215 } 213 } 216 217 private void fixRelation(Relation r) { 218 boolean replacedSomething = false; 219 LinkedList<RelationMember> newMembers = new LinkedList<RelationMember>(); 220 for (RelationMember m : r.members) { 221 OsmPrimitive otherP = mergedPrims.get(m.member); 222 if (otherP == null) { 223 newMembers.add(m); 224 } else { 225 RelationMember mnew = new RelationMember(m); 226 mnew.member = otherP; 227 newMembers.add(mnew); 228 replacedSomething = true; 229 } 230 } 231 if (replacedSomething) { 232 r.members.clear(); 233 r.members.addAll(newMembers); 234 } 235 } 214 236 215 237 /** … … 286 308 * @return <code>true</code>, if no merge is needed or merge is performed already. 287 309 */ 288 private <P extends OsmPrimitive> boolean mergeAfterId(Map< P,P> merged, Collection<P> primitives, P other) {310 private <P extends OsmPrimitive> boolean mergeAfterId(Map<OsmPrimitive,OsmPrimitive> merged, Collection<P> primitives, P other) { 289 311 for (P my : primitives) { 312 Date myd = my.timestamp == null ? new Date(0) : my.getTimestamp(); 313 Date otherd = other.timestamp == null ? new Date(0) : other.getTimestamp(); 290 314 if (my.realEqual(other, false)) { 291 315 if (merged != null) … … 297 321 if (merged != null) 298 322 merged.put(other, my); 299 if (my .getTimestamp().before(other.getTimestamp())) {323 if (myd.before(otherd)) { 300 324 my.modified = other.modified; 301 325 my.timestamp = other.timestamp; … … 304 328 } 305 329 if (my.id == other.id && my.id != 0) { 306 if (my.modified && other.modified) { 330 if (my.incomplete) { 331 return false; 332 } else if (my.modified && other.modified) { 307 333 conflicts.put(my, other); 308 if (merged != null)309 merged.put(other, my);310 334 } else if (!my.modified && !other.modified) { 311 if (my .getTimestamp().before(other.getTimestamp())) {335 if (myd.before(otherd)) { 312 336 cloneFromExceptIncomplete(my, other); 313 if (merged != null)314 merged.put(other, my);315 337 } 316 338 } else if (other.modified) { 317 if (my .getTimestamp().after(other.getTimestamp())) {339 if (myd.after(otherd)) { 318 340 conflicts.put(my, other); 319 if (merged != null)320 merged.put(other, my);321 341 } else { 322 342 cloneFromExceptIncomplete(my, other); 323 if (merged != null)324 merged.put(other, my);325 343 } 326 344 } else if (my.modified) { 327 if (my .getTimestamp().before(other.getTimestamp())) {345 if (myd.before(otherd)) { 328 346 conflicts.put(my, other); 329 if (merged != null)330 merged.put(other, my);331 }332 }347 } 348 } 349 if (merged != null) 350 merged.put(other, my); 333 351 return true; 334 352 }
Note:
See TracChangeset
for help on using the changeset viewer.