Changeset 15361 in josm


Ignore:
Timestamp:
2019-09-19T15:26:23+02:00 (5 years ago)
Author:
Don-vip
Message:

fix #18147, see #18006 - sort from/via/to members of restriction-alike relations

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/Relation.java

    r14905 r15361  
    1212import java.util.Set;
    1313import java.util.stream.Collectors;
     14import java.util.stream.Stream;
    1415
    1516import org.openstreetmap.josm.data.osm.visitor.OsmPrimitiveVisitor;
     
    540541     */
    541542    public Set<String> getMemberRoles() {
    542         Set<String> result = new HashSet<>();
    543         for (RelationMember rm : members) {
    544             String role = rm.getRole();
    545             if (!role.isEmpty()) {
    546                 result.add(role);
    547             }
    548         }
    549         return result;
     543        return Stream.of(members).map(RelationMember::getRole).filter(role -> !role.isEmpty()).collect(Collectors.toSet());
    550544    }
    551545}
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/sort/RelationSorter.java

    r14654 r15361  
    55import java.util.Arrays;
    66import java.util.Collection;
     7import java.util.Comparator;
    78import java.util.HashMap;
    89import java.util.LinkedHashMap;
     
    1112import java.util.Map;
    1213import java.util.Map.Entry;
     14import java.util.stream.Collectors;
    1315
    1416import org.openstreetmap.josm.data.osm.DefaultNameFormatter;
     
    2628
    2729    private interface AdditionalSorter {
    28         boolean acceptsMember(RelationMember m);
     30        boolean acceptsMember(List<RelationMember> relationMembers, RelationMember m);
    2931
    3032        List<RelationMember> sortMembers(List<RelationMember> list);
     
    3537        new AssociatedStreetRoleStreetSorter(),
    3638        new AssociatedStreetRoleAddressHouseSorter(),
    37         new PublicTransportRoleStopPlatformSorter()
     39        new PublicTransportRoleStopPlatformSorter(),
     40        new FromViaToSorter()
    3841    );
    3942
     
    4548
    4649        @Override
    47         public boolean acceptsMember(RelationMember m) {
     50        public boolean acceptsMember(List<RelationMember> relationMembers, RelationMember m) {
    4851            return "street".equals(m.getRole());
    4952        }
     
    6265
    6366        @Override
    64         public boolean acceptsMember(RelationMember m) {
     67        public boolean acceptsMember(List<RelationMember> relationMembers, RelationMember m) {
    6568            return "address".equals(m.getRole()) || "house".equals(m.getRole());
    6669        }
     
    9093
    9194        @Override
    92         public boolean acceptsMember(RelationMember m) {
     95        public boolean acceptsMember(List<RelationMember> relationMembers, RelationMember m) {
    9396            return m.getRole() != null && (m.getRole().startsWith("platform") || m.getRole().startsWith("stop"));
    9497        }
     
    133136
    134137    /**
     138     * Class that sorts the {@code from}, {@code via} and {@code to} members of
     139     * {@code type=restriction} relations.
     140     */
     141    private static class FromViaToSorter implements AdditionalSorter {
     142
     143        private static final List<String> ROLES = Arrays.asList("from", "via", "to");
     144
     145        @Override
     146        public boolean acceptsMember(List<RelationMember> relationMembers, RelationMember m) {
     147            return ROLES.contains(m.getRole())
     148                    && relationMembers.stream().map(RelationMember::getRole).collect(Collectors.toSet()).containsAll(ROLES);
     149        }
     150
     151        @Override
     152        public List<RelationMember> sortMembers(List<RelationMember> list) {
     153            list.sort(Comparator.comparingInt(m -> ROLES.indexOf(m.getRole())));
     154            return list;
     155        }
     156    }
     157
     158    /**
    135159     * Sort a collection of relation members by the way they are linked.
    136160     *
     
    150174            boolean wasAdded = false;
    151175            for (AdditionalSorter sorter : ADDITIONAL_SORTERS) {
    152                 if (sorter.acceptsMember(m)) {
     176                if (sorter.acceptsMember(relationMembers, m)) {
    153177                    wasAdded = customMap.computeIfAbsent(sorter, k -> new LinkedList<>()).add(m);
    154178                    break;
Note: See TracChangeset for help on using the changeset viewer.