Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/command/SplitWayCommand.java
r15276 r15362 19 19 import java.util.Set; 20 20 import java.util.function.Consumer; 21 import java.util.stream.Collectors; 21 22 22 23 import org.openstreetmap.josm.data.osm.DefaultNameFormatter; … … 426 427 String type = Optional.ofNullable(r.get("type")).orElse(""); 427 428 if ("from".equals(role) || "to".equals(role)) { 428 OsmPrimitive via = findVia(r, type);429 429 List<Node> nodes = new ArrayList<>(); 430 if (via != null) {430 for (OsmPrimitive via : findVias(r, type)) { 431 431 if (via instanceof Node) { 432 432 nodes.add((Node) via); … … 468 468 } 469 469 470 static OsmPrimitive findVia(Relation r, String type) {470 static List<OsmPrimitive> findVias(Relation r, String type) { 471 471 if (type != null) { 472 472 switch (type) { 473 case "connectivity": 473 474 case "restriction": 474 return findRelationMember (r, "via").orElse(null);475 return findRelationMembers(r, "via"); 475 476 case "destination_sign": 476 477 // Prefer intersection over sign, see #12347 477 return findRelationMember(r, "intersection").orElse(findRelationMember(r, "sign").orElse(null)); 478 List<OsmPrimitive> intersections = findRelationMembers(r, "intersection"); 479 return intersections.isEmpty() ? findRelationMembers(r, "sign") : intersections; 478 480 default: 479 return null;480 } 481 } 482 return null;483 } 484 485 static Optional<OsmPrimitive> findRelationMember(Relation r, String role) {481 break; 482 } 483 } 484 return Collections.emptyList(); 485 } 486 487 static List<OsmPrimitive> findRelationMembers(Relation r, String role) { 486 488 return r.getMembers().stream().filter(rmv -> role.equals(rmv.getRole())) 487 .map(RelationMember::getMember). findAny();489 .map(RelationMember::getMember).collect(Collectors.toList()); 488 490 } 489 491 -
trunk/test/unit/org/openstreetmap/josm/command/SplitWayCommandTest.java
r14134 r15362 3 3 4 4 import static org.junit.Assert.assertEquals; 5 import static org.junit.Assert.assertNull;6 5 import static org.junit.Assert.assertTrue; 7 6 8 7 import java.util.ArrayList; 9 8 import java.util.Arrays; 9 import java.util.Collections; 10 10 import java.util.Iterator; 11 11 … … 38 38 39 39 /** 40 * Unit test of {@link SplitWayCommand#findVia }.40 * Unit test of {@link SplitWayCommand#findVias}. 41 41 */ 42 42 @Test 43 public void testFindVia () {43 public void testFindVias() { 44 44 // empty relation 45 assert Null(SplitWayCommand.findVia(new Relation(), null));45 assertTrue(SplitWayCommand.findVias(new Relation(), null).isEmpty()); 46 46 // restriction relation without via member 47 47 Relation r = new Relation(); 48 48 r.addMember(new RelationMember("", new Node())); 49 assert Null(SplitWayCommand.findVia(r, "restriction"));49 assertTrue(SplitWayCommand.findVias(r, "restriction").isEmpty()); 50 50 // restriction relation with via member 51 51 r = new Relation(); 52 52 OsmPrimitive via = new Node(); 53 53 r.addMember(new RelationMember("via", via)); 54 assertEquals( via, SplitWayCommand.findVia(r, "restriction"));54 assertEquals(Collections.singletonList(via), SplitWayCommand.findVias(r, "restriction")); 55 55 // destination_sign relation without sign nor intersection 56 56 r = new Relation(); 57 57 r.addMember(new RelationMember("", new Node())); 58 assert Null(SplitWayCommand.findVia(r, "destination_sign"));58 assertTrue(SplitWayCommand.findVias(r, "destination_sign").isEmpty()); 59 59 // destination_sign with sign 60 60 r = new Relation(); 61 61 via = new Node(); 62 62 r.addMember(new RelationMember("sign", via)); 63 assertEquals( via, SplitWayCommand.findVia(r, "destination_sign"));63 assertEquals(Collections.singletonList(via), SplitWayCommand.findVias(r, "destination_sign")); 64 64 // destination_sign with intersection 65 65 r = new Relation(); 66 66 via = new Node(); 67 67 r.addMember(new RelationMember("intersection", via)); 68 assertEquals( via, SplitWayCommand.findVia(r, "destination_sign"));68 assertEquals(Collections.singletonList(via), SplitWayCommand.findVias(r, "destination_sign")); 69 69 } 70 70
Note:
See TracChangeset
for help on using the changeset viewer.