Changeset 15418 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2019-10-05T15:51:53+02:00 (5 years ago)
Author:
Don-vip
Message:

fix #14253 - Highlight affected relation members in role validation warnings

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

Legend:

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

    r15362 r15418  
    1919import java.util.Set;
    2020import java.util.function.Consumer;
    21 import java.util.stream.Collectors;
    2221
    2322import org.openstreetmap.josm.data.osm.DefaultNameFormatter;
     
    468467    }
    469468
    470     static List<OsmPrimitive> findVias(Relation r, String type) {
     469    static List<? extends OsmPrimitive> findVias(Relation r, String type) {
    471470        if (type != null) {
    472471            switch (type) {
    473472            case "connectivity":
    474473            case "restriction":
    475                 return findRelationMembers(r, "via");
     474                return r.findRelationMembers("via");
    476475            case "destination_sign":
    477476                // Prefer intersection over sign, see #12347
    478                 List<OsmPrimitive> intersections = findRelationMembers(r, "intersection");
    479                 return intersections.isEmpty() ? findRelationMembers(r, "sign") : intersections;
     477                List<? extends OsmPrimitive> intersections = r.findRelationMembers("intersection");
     478                return intersections.isEmpty() ? r.findRelationMembers("sign") : intersections;
    480479            default:
    481480                break;
     
    483482        }
    484483        return Collections.emptyList();
    485     }
    486 
    487     static List<OsmPrimitive> findRelationMembers(Relation r, String role) {
    488         return r.getMembers().stream().filter(rmv -> role.equals(rmv.getRole()))
    489                 .map(RelationMember::getMember).collect(Collectors.toList());
    490484    }
    491485
  • trunk/src/org/openstreetmap/josm/data/osm/DataSet.java

    r15404 r15418  
    2323import java.util.function.Function;
    2424import java.util.function.Predicate;
     25import java.util.stream.Collectors;
    2526import java.util.stream.Stream;
    2627
     
    214215            for (Relation r : relations) {
    215216                Relation newRelation = (Relation) primMap.get(r);
    216                 List<RelationMember> newMembers = new ArrayList<>();
    217                 for (RelationMember rm : r.getMembers()) {
    218                     newMembers.add(new RelationMember(rm.getRole(), primMap.get(rm.getMember())));
    219                 }
    220                 newRelation.setMembers(newMembers);
     217                newRelation.setMembers(r.getMembers().stream()
     218                        .map(rm -> new RelationMember(rm.getRole(), primMap.get(rm.getMember())))
     219                        .collect(Collectors.toList()));
    221220            }
    222221            for (DataSource source : copyFrom.dataSources) {
  • trunk/src/org/openstreetmap/josm/data/osm/DataSetMerger.java

    r15127 r15418  
    274274                throw new IllegalStateException(tr("Missing merge target of type {0} with id {1}",
    275275                        sourceMember.getType(), sourceMember.getUniqueId()));
    276             RelationMember newMember = new RelationMember(sourceMember.getRole(), targetMember);
    277             newMembers.add(newMember);
     276            newMembers.add(new RelationMember(sourceMember.getRole(), targetMember));
    278277            if (targetMember.isDeleted() && !conflicts.hasConflictForMy(targetMember)) {
    279278                addConflict(new Conflict<>(targetMember, sourceMember.getMember(), true));
  • trunk/src/org/openstreetmap/josm/data/osm/IRelation.java

    r13957 r15418  
    66import java.util.List;
    77import java.util.Set;
     8import java.util.stream.Collectors;
    89
    910import org.openstreetmap.josm.tools.Utils;
     
    124125        return ret;
    125126    }
     127
     128    /**
     129     * Returns a list of relation members having the specified role.
     130     * @param role role
     131     * @return a list of relation members having the specified role
     132     * @since 15418
     133     */
     134    default List<? extends IPrimitive> findRelationMembers(String role) {
     135        return getMembers().stream().filter(rmv -> role.equals(rmv.getRole()))
     136                .map(IRelationMember::getMember).collect(Collectors.toList());
     137    }
    126138}
  • trunk/src/org/openstreetmap/josm/data/osm/Relation.java

    r15361 r15418  
    543543        return Stream.of(members).map(RelationMember::getRole).filter(role -> !role.isEmpty()).collect(Collectors.toSet());
    544544    }
     545
     546    @Override
     547    public List<? extends OsmPrimitive> findRelationMembers(String role) {
     548        return IRelation.super.findRelationMembers(role).stream()
     549                .filter(m -> m instanceof OsmPrimitive)
     550                .map(m -> (OsmPrimitive) m).collect(Collectors.toList());
     551    }
    545552}
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/MergeSourceBuildingVisitor.java

    r13907 r15418  
    66import java.util.List;
    77import java.util.Map;
     8import java.util.stream.Collectors;
    89
    910import org.openstreetmap.josm.data.osm.DataSet;
     
    100101        }
    101102
    102         List<RelationMemberData> newMembers = new ArrayList<>();
    103         for (RelationMember member: r.getMembers()) {
    104             newMembers.add(new RelationMemberData(member.getRole(), mappedPrimitives.get(member.getMember())));
    105 
    106         }
    107         clone.setMembers(newMembers);
     103        clone.setMembers(r.getMembers().stream()
     104                .map(m -> new RelationMemberData(m.getRole(), mappedPrimitives.get(m.getMember())))
     105                .collect(Collectors.toList()));
    108106    }
    109107
  • trunk/src/org/openstreetmap/josm/data/validation/tests/RelationChecker.java

    r14990 r15418  
    55import static org.openstreetmap.josm.tools.I18n.tr;
    66
     7import java.util.ArrayList;
    78import java.util.Collection;
    89import java.util.EnumSet;
     
    1011import java.util.LinkedHashMap;
    1112import java.util.LinkedList;
     13import java.util.List;
    1214import java.util.Map;
    1315import java.util.stream.Collectors;
     
    317319        // verify unwanted members
    318320        for (String key : map.keySet()) {
    319             boolean found = false;
    320             for (Role r: allroles.keySet()) {
    321                 if (r.isRole(key)) {
    322                     found = true;
    323                     break;
    324                 }
    325             }
    326 
    327             if (!found) {
     321            if (allroles.keySet().stream().noneMatch(role -> role.isRole(key))) {
    328322                String templates = allroles.keySet().stream().map(r -> r.key).collect(Collectors.joining("/"));
     323                List<OsmPrimitive> primitives = new ArrayList<>(n.findRelationMembers(key));
     324                primitives.add(0, n);
    329325
    330326                if (!key.isEmpty()) {
    331327                    errors.add(TestError.builder(this, Severity.WARNING, ROLE_UNKNOWN)
    332328                            .message(ROLE_VERIF_PROBLEM_MSG, marktr("Role ''{0}'' is not in templates ''{1}''"), key, templates)
    333                             .primitives(n)
     329                            .primitives(primitives)
    334330                            .build());
    335331                } else {
    336332                    errors.add(TestError.builder(this, Severity.WARNING, ROLE_EMPTY)
    337333                            .message(ROLE_VERIF_PROBLEM_MSG, marktr("Empty role found when expecting one of ''{0}''"), templates)
    338                             .primitives(n)
     334                            .primitives(primitives)
    339335                            .build());
    340336                }
  • trunk/src/org/openstreetmap/josm/gui/datatransfer/RelationMemberTransferable.java

    r12663 r15418  
    1111import java.util.Collections;
    1212import java.util.HashSet;
     13import java.util.stream.Collectors;
    1314
    1415import org.openstreetmap.josm.data.osm.DefaultNameFormatter;
     
    5152         */
    5253        public static Data getData(Collection<RelationMember> members) {
    53             final Collection<RelationMemberData> r = new ArrayList<>(members.size());
    54             for (RelationMember member : members) {
    55                 r.add(new RelationMemberData(member.getRole(), member.getType(), member.getUniqueId()));
    56             }
    57             return new Data(r);
     54            return new Data(members.stream()
     55                    .map(m -> new RelationMemberData(m.getRole(), m.getType(), m.getUniqueId()))
     56                    .collect(Collectors.toList()));
    5857        }
    5958    }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/sort/RelationSorter.java

    r15361 r15418  
    6666        @Override
    6767        public boolean acceptsMember(List<RelationMember> relationMembers, RelationMember m) {
    68             return "address".equals(m.getRole()) || "house".equals(m.getRole());
     68            return m.hasRole("address", "house");
    6969        }
    7070
Note: See TracChangeset for help on using the changeset viewer.