Ticket #19956: 19956.patch
| File 19956.patch, 7.3 KB (added by , 5 years ago) |
|---|
-
src/org/openstreetmap/josm/data/validation/tests/DuplicateRelation.java
28 28 import org.openstreetmap.josm.data.validation.Severity; 29 29 import org.openstreetmap.josm.data.validation.Test; 30 30 import org.openstreetmap.josm.data.validation.TestError; 31 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 31 32 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 32 33 import org.openstreetmap.josm.tools.MultiMap; 33 34 … … 201 202 202 203 @Override 203 204 public void endTest() { 204 super.endTest();205 205 for (Set<OsmPrimitive> duplicated : relations.values()) { 206 206 if (duplicated.size() > 1) { 207 207 TestError testError = TestError.builder(this, Severity.ERROR, DUPLICATE_RELATION) … … 222 222 } 223 223 } 224 224 relationsNoKeys = null; 225 super.endTest(); 225 226 } 226 227 227 228 @Override … … 245 246 */ 246 247 @Override 247 248 public Command fixError(TestError testError) { 248 if (testError.getCode() == SAME_RELATION) return null; 249 Set<Relation> relFix = testError.primitives(Relation.class) 250 .filter(r -> !r.isDeleted()) 249 if (!isFixable(testError)) 250 return null; 251 Set<Relation> toFix = testError.primitives(Relation.class) 252 .filter(this::isPrimitiveUsable) 251 253 .collect(Collectors.toSet()); 252 254 253 if ( relFix.size() < 2)255 if (toFix.size() < 2) 254 256 return null; 255 257 258 // see #19956 check again 259 Test test2 = new DuplicateRelation(); 260 test2.startTest(NullProgressMonitor.INSTANCE); 261 toFix.forEach(test2::visit); 262 test2.endTest(); 263 boolean errorStillExists = false; 264 for (TestError e : test2.getErrors()) { 265 if (e.getCode() == testError.getCode() && e.getPrimitives().size() >= 2) { 266 // refresh primitives, might be fewer than before 267 toFix = e.primitives(Relation.class).collect(Collectors.toSet()); 268 errorStillExists = true; 269 break; 270 } 271 } 272 if (!errorStillExists) 273 return null; 274 256 275 long idToKeep = 0; 257 Relation relationToKeep = relFix.iterator().next();276 Relation relationToKeep = toFix.iterator().next(); 258 277 // Find the relation that is member of one or more relations. (If any) 259 278 Relation relationWithRelations = null; 260 279 Collection<Relation> relRef = null; 261 for (Relation w : relFix) {262 Collection<Relation> rel = w.referrers(Relation.class).collect(Collectors.toList());280 for (Relation r : toFix) { 281 Collection<Relation> rel = r.referrers(Relation.class).collect(Collectors.toList()); 263 282 if (!rel.isEmpty()) { 264 283 if (relationWithRelations != null) 265 284 throw new AssertionError("Cannot fix duplicate relations: More than one relation is member of another relation."); 266 relationWithRelations = w;285 relationWithRelations = r; 267 286 relRef = rel; 268 287 } 269 288 // Only one relation will be kept - the one with lowest positive ID, if such exist 270 289 // or one "at random" if no such exists. Rest of the relations will be deleted 271 if (! w.isNew() && (idToKeep == 0 || w.getId() < idToKeep)) {272 idToKeep = w.getId();273 relationToKeep = w;290 if (!r.isNew() && (idToKeep == 0 || r.getId() < idToKeep)) { 291 idToKeep = r.getId(); 292 relationToKeep = r; 274 293 } 275 294 } 276 295 … … 291 310 } 292 311 293 312 // Delete all relations in the list 294 relFix.remove(relationToKeep);295 commands.add(new DeleteCommand( relFix));313 toFix.remove(relationToKeep); 314 commands.add(new DeleteCommand(toFix)); 296 315 return new SequenceCommand(tr("Delete duplicate relations"), commands); 297 316 } 298 317 -
src/org/openstreetmap/josm/data/validation/tests/DuplicateWay.java
29 29 import org.openstreetmap.josm.data.validation.Severity; 30 30 import org.openstreetmap.josm.data.validation.Test; 31 31 import org.openstreetmap.josm.data.validation.TestError; 32 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 32 33 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 33 34 import org.openstreetmap.josm.tools.MultiMap; 34 35 … … 122 123 123 124 @Override 124 125 public void endTest() { 125 super.endTest();126 126 for (Set<OsmPrimitive> duplicated : ways.values()) { 127 127 if (duplicated.size() > 1) { 128 128 TestError testError = TestError.builder(this, Severity.ERROR, DUPLICATE_WAY) … … 165 165 ways = null; 166 166 waysNoTags = null; 167 167 knownHashCodes = null; 168 super.endTest(); 168 169 } 169 170 170 171 /** … … 249 250 */ 250 251 @Override 251 252 public Command fixError(TestError testError) { 252 Set<Way> wayz = testError.primitives(Way.class) 253 .filter(w -> !w.isDeleted()) 253 if (!isFixable(testError)) 254 return null; 255 256 Set<Way> toFix = testError.primitives(Way.class) 257 .filter(this::isPrimitiveUsable) 254 258 .collect(Collectors.toSet()); 255 259 256 if ( wayz.size() < 2)260 if (toFix.size() < 2) 257 261 return null; 258 262 263 // see #19956 check again 264 Test test2 = new DuplicateWay(); 265 test2.startTest(NullProgressMonitor.INSTANCE); 266 toFix.forEach(test2::visit); 267 test2.endTest(); 268 boolean errorStillExists = false; 269 for (TestError e : test2.getErrors()) { 270 if (e.getCode() == testError.getCode() && e.getPrimitives().size() >= 2) { 271 // refresh primitives, might be fewer than before 272 toFix = e.primitives(Way.class).collect(Collectors.toSet()); 273 errorStillExists = true; 274 break; 275 } 276 } 277 if (!errorStillExists) 278 return null; 279 259 280 long idToKeep = 0; 260 Way wayToKeep = wayz.iterator().next();281 Way wayToKeep = toFix.iterator().next(); 261 282 // Find the way that is member of one or more relations. (If any) 262 283 Way wayWithRelations = null; 263 284 List<Relation> relations = null; 264 for (Way w : wayz) {285 for (Way w : toFix) { 265 286 List<Relation> rel = w.referrers(Relation.class).collect(Collectors.toList()); 266 287 if (!rel.isEmpty()) { 267 288 if (wayWithRelations != null) … … 295 316 296 317 // Delete all ways in the list 297 318 // Note: nodes are not deleted, these can be detected and deleted at next pass 298 wayz.remove(wayToKeep);299 commands.add(new DeleteCommand( wayz));319 toFix.remove(wayToKeep); 320 commands.add(new DeleteCommand(toFix)); 300 321 return new SequenceCommand(tr("Delete duplicate ways"), commands); 301 322 } 302 323
