- Timestamp:
- 2020-10-19T15:25:47+02:00 (4 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/data/validation/tests
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/validation/tests/DuplicateRelation.java
r16445 r17243 14 14 import java.util.stream.Collectors; 15 15 16 import org.openstreetmap.josm.command.Change Command;16 import org.openstreetmap.josm.command.ChangeMembersCommand; 17 17 import org.openstreetmap.josm.command.Command; 18 18 import org.openstreetmap.josm.command.DeleteCommand; … … 202 202 @Override 203 203 public void endTest() { 204 super.endTest();205 204 for (Set<OsmPrimitive> duplicated : relations.values()) { 206 205 if (duplicated.size() > 1) { … … 223 222 } 224 223 relationsNoKeys = null; 224 super.endTest(); 225 225 } 226 226 … … 246 246 @Override 247 247 public Command fixError(TestError testError) { 248 if (testError.getCode() == SAME_RELATION) return null; 248 if (!isFixable(testError)) return null; 249 249 250 Set<Relation> relFix = testError.primitives(Relation.class) 250 .filter(r -> !r.isDeleted() )251 .filter(r -> !r.isDeleted() || r.getDataSet() == null || r.getDataSet().getPrimitiveById(r) == null) 251 252 .collect(Collectors.toSet()); 252 253 … … 259 260 Relation relationWithRelations = null; 260 261 Collection<Relation> relRef = null; 261 for (Relation w: relFix) {262 Collection<Relation> rel = w.referrers(Relation.class).collect(Collectors.toList());262 for (Relation r : relFix) { 263 Collection<Relation> rel = r.referrers(Relation.class).collect(Collectors.toList()); 263 264 if (!rel.isEmpty()) { 264 265 if (relationWithRelations != null) 265 266 throw new AssertionError("Cannot fix duplicate relations: More than one relation is member of another relation."); 266 relationWithRelations = w;267 relationWithRelations = r; 267 268 relRef = rel; 268 269 } 269 270 // Only one relation will be kept - the one with lowest positive ID, if such exist 270 271 // 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;272 if (!r.isNew() && (idToKeep == 0 || r.getId() < idToKeep)) { 273 idToKeep = r.getId(); 274 relationToKeep = r; 274 275 } 275 276 } … … 280 281 if (relationWithRelations != null && relRef != null && relationToKeep != relationWithRelations) { 281 282 for (Relation rel : relRef) { 282 Relation newRel = new Relation(rel);283 for (int i = 0; i < newRel.getMembers().size(); ++i) {284 RelationMember m = newRel.getMember(i);283 List<RelationMember> members = new ArrayList<>(rel.getMembers()); 284 for (int i = 0; i < rel.getMembers().size(); ++i) { 285 RelationMember m = rel.getMember(i); 285 286 if (relationWithRelations.equals(m.getMember())) { 286 newRel.setMember(i, new RelationMember(m.getRole(), relationToKeep));287 members.set(i, new RelationMember(m.getRole(), relationToKeep)); 287 288 } 288 289 } 289 commands.add(new Change Command(rel, newRel));290 commands.add(new ChangeMembersCommand(rel, members)); 290 291 } 291 292 } -
trunk/src/org/openstreetmap/josm/data/validation/tests/DuplicateWay.java
r16445 r17243 16 16 import java.util.stream.IntStream; 17 17 18 import org.openstreetmap.josm.command.Change Command;18 import org.openstreetmap.josm.command.ChangeMembersCommand; 19 19 import org.openstreetmap.josm.command.Command; 20 20 import org.openstreetmap.josm.command.DeleteCommand; … … 283 283 if (wayWithRelations != null && relations != null && wayToKeep != wayWithRelations) { 284 284 for (Relation rel : relations) { 285 Relation newRel = new Relation(rel);286 for (int i = 0; i < newRel.getMembers().size(); ++i) {287 RelationMember m = newRel.getMember(i);285 List<RelationMember> members = rel.getMembers(); 286 for (int i = 0; i < rel.getMembers().size(); ++i) { 287 RelationMember m = rel.getMember(i); 288 288 if (wayWithRelations.equals(m.getMember())) { 289 newRel.setMember(i, new RelationMember(m.getRole(), wayToKeep));289 members.set(i, new RelationMember(m.getRole(), wayToKeep)); 290 290 } 291 291 } 292 commands.add(new Change Command(rel, newRel));292 commands.add(new ChangeMembersCommand(rel, members)); 293 293 } 294 294 } -
trunk/src/org/openstreetmap/josm/data/validation/tests/RelationChecker.java
r16793 r17243 18 18 import java.util.stream.Collectors; 19 19 20 import org.openstreetmap.josm.command.Change Command;20 import org.openstreetmap.josm.command.ChangeMembersCommand; 21 21 import org.openstreetmap.josm.command.Command; 22 22 import org.openstreetmap.josm.command.DeleteCommand; … … 386 386 if (testError.getCode() == RELATION_LOOP) { 387 387 Relation old = (Relation) primitives.iterator().next(); 388 Relation mod = new Relation(old);389 mod.removeMembersFor(primitives);390 return new Change Command(old, mod);388 List<RelationMember> remaining = new ArrayList<>(old.getMembers()); 389 remaining.removeIf(rm -> primitives.contains(rm.getMember())); 390 return new ChangeMembersCommand(old, Utils.toUnmodifiableList(remaining)); 391 391 } 392 392 }
Note:
See TracChangeset
for help on using the changeset viewer.