Changeset 371 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2007-10-12T15:52:32+02:00 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/visitor/MergeVisitor.java
r369 r371 34 34 35 35 /** 36 * A list of all nodes that got replaced with other nodes.37 * Key is the nodein the other's dataset and the value is the one that is now36 * A list of all primitives that got replaced with other primitives. 37 * Key is the primitives in the other's dataset and the value is the one that is now 38 38 * in ds.nodes instead. 39 39 */ … … 76 76 } 77 77 78 private <T extends OsmPrimitive> void cloneFromExceptIncomplete(T myOsm, T otherOsm) {79 if (myOsm instanceof Way) {80 Way my = (Way)myOsm;81 Way other = (Way)otherOsm;82 HashMap<Long, Node> copy = new HashMap<Long, Node>();83 for (Node n : my.nodes)84 copy.put(n.id, n);85 my.cloneFrom(other);86 my.nodes.clear();87 for (Node n : other.nodes) {88 Node myN = copy.get(n.id);89 if (n.incomplete && myN != null && !myN.incomplete) {90 merged.put(n, myN);91 my.nodes.add(myN);92 } else93 my.nodes.add(n);94 }95 } else if (myOsm instanceof Relation) {96 Relation my = (Relation)myOsm;97 Relation other = (Relation)otherOsm;98 99 HashMap<Long, OsmPrimitive>[] copy =100 (HashMap<Long, OsmPrimitive>[]) new HashMap[3];101 for (int i = 0; i < 3; i++) copy[i] = new HashMap<Long, OsmPrimitive>();102 103 for (RelationMember m : my.members) {104 int i;105 if (m.member instanceof Node) i = 0; else106 if (m.member instanceof Way) i = 1; else107 if (m.member instanceof Relation) i = 2; else i = 3;108 copy[i].put(m.member.id, m.member);109 }110 111 my.cloneFrom(other);112 my.members.clear();113 for (RelationMember m : other.members) {114 int i;115 if (m.member instanceof Node) i = 0; else116 if (m.member instanceof Way) i = 1; else117 if (m.member instanceof Relation) i = 2; else i = 3;118 OsmPrimitive myP = copy[i].get(m.member.id);119 if (m.member.incomplete && myP != null && !myP.incomplete) {120 RelationMember mnew = new RelationMember(m);121 mnew.member = myP;122 my.members.add(mnew);123 merged.put(m.member, mnew.member);124 } else {125 my.members.add(m);126 }127 }128 } else {129 myOsm.cloneFrom(otherOsm);130 }131 }132 133 78 /** 134 79 * Merge the way if id matches or if all nodes match and the … … 149 94 if (my == null) { 150 95 ds.ways.add(other); 151 } else if (my.incomplete && !other.incomplete) {152 merged.put(other, my);153 my.cloneFrom(other);154 } else if (other.incomplete && !my.incomplete) {155 merged.put(other, my);156 96 } else { 157 97 merged.put(other, my); … … 166 106 } 167 107 if (!same) { 168 my.nodes.clear();169 my.nodes.addAll(other.nodes);170 108 my.modified = other.modified; 171 109 } … … 191 129 192 130 if (my == null) { 193 // Add the relation and replace any incomplete segments that we already have131 // Add the relation 194 132 ds.relations.add(other); 195 /*for (RelationMember em : other.members) {196 if (em.member.incomplete) {197 if (em.member instanceof Node) {198 for (Node ourN : ds.nodes) {199 if (ourN.id == em.member.id) {200 merged.put(em.member, ourN);201 break;202 }203 }204 } else if (em.member instanceof Way) {205 for (Way ourW : ds.ways) {206 if (ourW.id == em.member.id) {207 merged.put(em.member, ourW);208 break;209 }210 }211 } else if (em.member instanceof Relation) {212 for (Relation ourR : ds.relations) {213 if (ourR.id == em.member.id) {214 merged.put(em.member, ourR);215 break;216 }217 }218 }219 }220 }*/221 133 } else { 222 134 merged.put(other, my); … … 236 148 } 237 149 if (!same) { 238 /*HashMap<Long, OsmPrimitive>[] copy =239 (HashMap<Long, OsmPrimitive>[]) new HashMap[3];240 for (int i = 0; i < 3; i++) copy[i] = new HashMap<Long, OsmPrimitive>();241 242 for (RelationMember m : my.members) {243 int i;244 if (m.member instanceof Node) i = 0; else245 if (m.member instanceof Way) i = 1; else246 if (m.member instanceof Relation) i = 2; else i = 3;247 copy[i].put(m.member.id, m.member);248 }249 250 my.cloneFrom(other);251 my.members.clear();252 for (RelationMember m : other.members) {253 int i;254 if (m.member instanceof Node) i = 0; else255 if (m.member instanceof Way) i = 1; else256 if (m.member instanceof Relation) i = 2; else i = 3;257 OsmPrimitive myP = copy[i].get(m.member.id);258 if (m.member.incomplete && myP != null && !myP.incomplete) {259 RelationMember mnew = new RelationMember(m);260 mnew.member = myP;261 my.members.add(mnew);262 merged.put(m.member, mnew.member);263 } else {264 my.members.add(m);265 }266 }*/267 150 my.modified = other.modified; 268 151 } … … 414 297 my.cloneFrom(other); 415 298 } 416 merged.put(other, my);417 299 } else if (my.modified && other.modified) { 418 300 conflicts.put(my, other); 419 merged.put(other, my);420 301 } else if (!my.modified && !other.modified) { 421 302 if (myd.before(otherd)) { 422 cloneFromExceptIncomplete(my, other); 423 merged.put(other, my); 303 my.cloneFrom(other); 424 304 } 425 305 } else if (other.modified) { 426 306 if (myd.after(otherd)) { 427 307 conflicts.put(my, other); 428 merged.put(other, my);429 308 } else { 430 cloneFromExceptIncomplete(my, other); 431 merged.put(other, my); 309 my.cloneFrom(other); 432 310 } 433 311 } else if (my.modified) { 434 312 if (myd.before(otherd)) { 435 313 conflicts.put(my, other); 436 merged.put(other, my);437 314 } 438 315 } 316 merged.put(other, my); 439 317 return true; 440 318 }
Note:
See TracChangeset
for help on using the changeset viewer.