Changeset 15362 in josm for trunk


Ignore:
Timestamp:
2019-09-19T16:01:03+02:00 (5 years ago)
Author:
Don-vip
Message:

fix #18088 - see #18006 - Allow splitting a connectivity/restriction relation with multiple via-ways

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/command/SplitWayCommand.java

    r15276 r15362  
    1919import java.util.Set;
    2020import java.util.function.Consumer;
     21import java.util.stream.Collectors;
    2122
    2223import org.openstreetmap.josm.data.osm.DefaultNameFormatter;
     
    426427        String type = Optional.ofNullable(r.get("type")).orElse("");
    427428        if ("from".equals(role) || "to".equals(role)) {
    428             OsmPrimitive via = findVia(r, type);
    429429            List<Node> nodes = new ArrayList<>();
    430             if (via != null) {
     430            for (OsmPrimitive via : findVias(r, type)) {
    431431                if (via instanceof Node) {
    432432                    nodes.add((Node) via);
     
    468468    }
    469469
    470     static OsmPrimitive findVia(Relation r, String type) {
     470    static List<OsmPrimitive> findVias(Relation r, String type) {
    471471        if (type != null) {
    472472            switch (type) {
     473            case "connectivity":
    473474            case "restriction":
    474                 return findRelationMember(r, "via").orElse(null);
     475                return findRelationMembers(r, "via");
    475476            case "destination_sign":
    476477                // 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;
    478480            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) {
    486488        return r.getMembers().stream().filter(rmv -> role.equals(rmv.getRole()))
    487                 .map(RelationMember::getMember).findAny();
     489                .map(RelationMember::getMember).collect(Collectors.toList());
    488490    }
    489491
  • trunk/test/unit/org/openstreetmap/josm/command/SplitWayCommandTest.java

    r14134 r15362  
    33
    44import static org.junit.Assert.assertEquals;
    5 import static org.junit.Assert.assertNull;
    65import static org.junit.Assert.assertTrue;
    76
    87import java.util.ArrayList;
    98import java.util.Arrays;
     9import java.util.Collections;
    1010import java.util.Iterator;
    1111
     
    3838
    3939    /**
    40      * Unit test of {@link SplitWayCommand#findVia}.
     40     * Unit test of {@link SplitWayCommand#findVias}.
    4141     */
    4242    @Test
    43     public void testFindVia() {
     43    public void testFindVias() {
    4444        // empty relation
    45         assertNull(SplitWayCommand.findVia(new Relation(), null));
     45        assertTrue(SplitWayCommand.findVias(new Relation(), null).isEmpty());
    4646        // restriction relation without via member
    4747        Relation r = new Relation();
    4848        r.addMember(new RelationMember("", new Node()));
    49         assertNull(SplitWayCommand.findVia(r, "restriction"));
     49        assertTrue(SplitWayCommand.findVias(r, "restriction").isEmpty());
    5050        // restriction relation with via member
    5151        r = new Relation();
    5252        OsmPrimitive via = new Node();
    5353        r.addMember(new RelationMember("via", via));
    54         assertEquals(via, SplitWayCommand.findVia(r, "restriction"));
     54        assertEquals(Collections.singletonList(via), SplitWayCommand.findVias(r, "restriction"));
    5555        // destination_sign relation without sign nor intersection
    5656        r = new Relation();
    5757        r.addMember(new RelationMember("", new Node()));
    58         assertNull(SplitWayCommand.findVia(r, "destination_sign"));
     58        assertTrue(SplitWayCommand.findVias(r, "destination_sign").isEmpty());
    5959        // destination_sign with sign
    6060        r = new Relation();
    6161        via = new Node();
    6262        r.addMember(new RelationMember("sign", via));
    63         assertEquals(via, SplitWayCommand.findVia(r, "destination_sign"));
     63        assertEquals(Collections.singletonList(via), SplitWayCommand.findVias(r, "destination_sign"));
    6464        // destination_sign with intersection
    6565        r = new Relation();
    6666        via = new Node();
    6767        r.addMember(new RelationMember("intersection", via));
    68         assertEquals(via, SplitWayCommand.findVia(r, "destination_sign"));
     68        assertEquals(Collections.singletonList(via), SplitWayCommand.findVias(r, "destination_sign"));
    6969    }
    7070
Note: See TracChangeset for help on using the changeset viewer.