Changeset 17621 in josm for trunk


Ignore:
Timestamp:
2021-03-21T15:45:26+01:00 (4 years ago)
Author:
simon04
Message:

see #19180 - Fix code duplication

Location:
trunk/src/org/openstreetmap/josm/data/validation/tests
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java

    r17620 r17621  
    2121import java.util.Set;
    2222import java.util.function.Consumer;
     23import java.util.function.Predicate;
    2324import java.util.stream.Stream;
    2425
     
    386387    @Override
    387388    public void visit(Collection<OsmPrimitive> selection) {
    388         if (progressMonitor != null) {
     389        visit(selection, null);
     390    }
     391
     392    /**
     393     * Execute the rules from the URLs matching the given predicate.
     394     * @param selection collection of primitives
     395     * @param urlPredicate a predicate deciding whether the rules from the given URL shall be executed
     396     */
     397    void visit(Collection<OsmPrimitive> selection, Predicate<String> urlPredicate) {
     398        if (urlPredicate == null && progressMonitor != null) {
    389399            progressMonitor.setTicksCount(selection.size() * checks.size());
    390400        }
     
    396406            if (isCanceled()) {
    397407                break;
     408            }
     409            if (urlPredicate != null && !urlPredicate.test(entry.getKey())) {
     410                continue;
    398411            }
    399412            visit(entry.getKey(), entry.getValue(), selection, surrounding);
     
    480493    }
    481494
    482     /**
    483      * Execute only the rules for the rules matching the given file name. See #19180
    484      * @param ruleFile the name of the mapcss file, e.g. deprecated.mapcss
    485      * @param selection collection of primitives
    486      * @since 16784
    487      */
    488     public void runOnly(String ruleFile, Collection<OsmPrimitive> selection) {
    489         mpAreaCache.clear();
    490 
    491         Set<OsmPrimitive> surrounding = new HashSet<>();
    492         for (Entry<String, Set<MapCSSTagCheckerRule>> entry : checks.entrySet()) {
    493             if (isCanceled()) {
    494                 break;
    495             }
    496             if (entry.getKey().endsWith(ruleFile)) {
    497                 visit(entry.getKey(), entry.getValue(), selection, surrounding);
    498             }
    499         }
    500 
    501     }
    502495}
  • trunk/src/org/openstreetmap/josm/data/validation/tests/TagChecker.java

    r17584 r17621  
    10431043            return 0;
    10441044        deprecatedChecker.getErrors().clear();
    1045         deprecatedChecker.runOnly("deprecated.mapcss", Collections.singleton(p));
     1045        deprecatedChecker.visit(Collections.singleton(p), url -> url.endsWith("deprecated.mapcss"));
    10461046        return deprecatedChecker.getErrors().size();
    10471047    }
Note: See TracChangeset for help on using the changeset viewer.