Ticket #17011: 17011-suppress-dups.patch

File 17011-suppress-dups.patch, 1.8 KB (added by GerdP, 7 years ago)

Suppress duplicate messages from MapCSSTagChecker where only the order of primitives is different

  • src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java

     
    864864                    if (!ignoreError && !check.errors.isEmpty()) {
    865865                        final TestError error = check.getErrorForPrimitive(p, r.selector, env, new MapCSSTagCheckerAndRule(check.rule));
    866866                        if (error != null) {
    867                             res.add(error);
     867                            addIfNotDuplicate(error, errors);
    868868                        }
    869869                    }
    870870
     
    874874        return res;
    875875    }
    876876
     877    private static void addIfNotDuplicate(TestError toAdd, List<TestError> errors) {
     878        boolean isDup = false;
     879        if (toAdd.getPrimitives().size() >= 2) {
     880            // make sure that we don't report the same error for the same combination of primitives in different order
     881            for (TestError e : errors) {
     882                if (e.getCode() == toAdd.getCode() && e.getMessage().equals(toAdd.getMessage())
     883                        && e.getPrimitives().size() == toAdd.getPrimitives().size()
     884                        && e.getPrimitives().containsAll(toAdd.getPrimitives())) {
     885                    isDup = true;
     886                    break;
     887                }
     888            }
     889        }
     890        if (!isDup)
     891            errors.add(toAdd);
     892    }
     893
    877894    private static Collection<TestError> getErrorsForPrimitive(OsmPrimitive p, boolean includeOtherSeverity,
    878895            Collection<Set<TagCheck>> checksCol) {
    879896        final List<TestError> r = new ArrayList<>();