Ticket #13805: 13805-grouped.patch
| File 13805-grouped.patch, 6.8 KB (added by , 6 years ago) |
|---|
-
src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java
5 5 6 6 import java.awt.geom.Area; 7 7 import java.io.BufferedReader; 8 import java.io.File; 8 9 import java.io.IOException; 9 10 import java.io.InputStream; 10 11 import java.io.Reader; … … 17 18 import java.util.LinkedList; 18 19 import java.util.List; 19 20 import java.util.Map; 21 import java.util.Map.Entry; 20 22 import java.util.Objects; 21 23 import java.util.Optional; 22 24 import java.util.Set; … … 66 68 import org.openstreetmap.josm.tools.I18n; 67 69 import org.openstreetmap.josm.tools.Logging; 68 70 import org.openstreetmap.josm.tools.MultiMap; 71 import org.openstreetmap.josm.tools.Stopwatch; 69 72 import org.openstreetmap.josm.tools.Utils; 70 73 71 74 /** … … 75 78 public class MapCSSTagChecker extends Test.TagTest { 76 79 private MapCSSStyleIndex indexData; 77 80 final Map<MapCSSRule, MapCSSTagCheckerAndRule> ruleToCheckMap = new HashMap<>(); 78 private final Set<OsmPrimitive> tested = new HashSet<>();79 81 private static final Map<IPrimitive, Area> mpAreaCache = new HashMap<>(); 80 82 static final boolean ALL_TESTS = true; 81 83 static final boolean ONLY_SELECTED_TESTS = false; … … 762 764 for (TestError e : getErrorsForPrimitive(p, ValidatorPrefHelper.PREF_OTHER.get())) { 763 765 addIfNotSimilar(e, errors); 764 766 } 765 if (partialSelection) {766 tested.add(p);767 }768 767 } 769 768 770 769 /** … … 855 854 public synchronized void startTest(ProgressMonitor progressMonitor) { 856 855 super.startTest(progressMonitor); 857 856 super.setShowElements(true); 858 if (indexData == null) { 859 indexData = createMapCSSTagCheckerIndex(checks, includeOtherSeverityChecks(), ALL_TESTS); 857 } 858 859 @Override 860 public synchronized void endTest() { 861 // no need to keep the index, it is quickly build and doubles the memory needs 862 indexData = null; 863 // always clear the cache to make sure that we catch changes in geometry 864 mpAreaCache.clear(); 865 super.endTest(); 866 } 867 868 @Override 869 public void visit(Collection<OsmPrimitive> selection) { 870 if (progressMonitor != null) { 871 progressMonitor.setTicksCount(selection.size() * checks.size()); 860 872 } 861 tested.clear(); 873 862 874 mpAreaCache.clear(); 875 876 Set<OsmPrimitive> surrounding = new HashSet<>(); 877 for (Entry<String, Set<TagCheck>> entry : checks.entrySet()) { 878 if (isCanceled()) { 879 break; 880 } 881 visit(entry.getKey(), entry.getValue(), selection, surrounding); 882 } 863 883 } 864 884 865 @Override 866 public synchronized void endTest() { 885 /** 886 * Perform the checks for one check url 887 * @param url the url for the checks 888 * @param checksForUrl the checks to perform 889 * @param selection collection primitives 890 * @param surrounding surrounding primitives, evtl. filled by this routine 891 */ 892 private void visit(String url, Set<TagCheck> checksForUrl, Collection<OsmPrimitive> selection, 893 Set<OsmPrimitive> surrounding) { 894 MultiMap<String, TagCheck> currentCheck = new MultiMap<>(); 895 currentCheck.putAll(url, checksForUrl); 896 indexData = createMapCSSTagCheckerIndex(currentCheck, includeOtherSeverityChecks(), ALL_TESTS); 897 Set<OsmPrimitive> tested = new HashSet<>(); 898 899 900 String source = simplifySourceName(url); 901 if (progressMonitor != null) { 902 progressMonitor.setExtraText(tr(" {0}", source)); 903 } 904 long cnt = 0; 905 Stopwatch stopwatch = Stopwatch.createStarted(); 906 for (OsmPrimitive p : selection) { 907 if (isCanceled()) { 908 break; 909 } 910 if (isPrimitiveUsable(p)) { 911 check(p); 912 if (partialSelection) { 913 tested.add(p); 914 } 915 } 916 if (progressMonitor != null) { 917 progressMonitor.worked(1); 918 cnt++; 919 // add frequently changing info to progress monitor so that it 920 // doesn't seem to hang when test takes longer than 0.5 seconds 921 if (cnt % 10000 == 0 && stopwatch.elapsed() >= 500) { 922 progressMonitor 923 .setExtraText(tr(" {0}: {1} of {2} elements done", source, cnt, selection.size())); 924 } 925 } 926 } 927 867 928 if (partialSelection && !tested.isEmpty()) { 868 929 // #14287: see https://josm.openstreetmap.de/ticket/14287#comment:15 869 930 // execute tests for objects which might contain or cross previously tested elements … … 870 931 871 932 // rebuild index with a reduced set of rules (those that use ChildOrParentSelector) and thus may have left selectors 872 933 // matching the previously tested elements 873 indexData = createMapCSSTagCheckerIndex(c hecks, includeOtherSeverityChecks(), ONLY_SELECTED_TESTS);934 indexData = createMapCSSTagCheckerIndex(currentCheck, includeOtherSeverityChecks(), ONLY_SELECTED_TESTS); 874 935 875 Set<OsmPrimitive> surrounding = new HashSet<>(); 876 for (OsmPrimitive p : tested) { 877 if (p.getDataSet() != null) { 878 surrounding.addAll(p.getDataSet().searchWays(p.getBBox())); 879 surrounding.addAll(p.getDataSet().searchRelations(p.getBBox())); 936 if (surrounding.isEmpty()) { 937 for (OsmPrimitive p : tested) { 938 if (p.getDataSet() != null) { 939 surrounding.addAll(p.getDataSet().searchWays(p.getBBox())); 940 surrounding.addAll(p.getDataSet().searchRelations(p.getBBox())); 941 } 880 942 } 881 943 } 944 882 945 final boolean includeOtherSeverity = includeOtherSeverityChecks(); 883 946 for (OsmPrimitive p : surrounding) { 884 947 if (tested.contains(p)) … … 889 952 addIfNotSimilar(e, errors); 890 953 } 891 954 } 892 tested.clear();893 955 } 894 // no need to keep the index, it is quickly build and doubles the memory needs895 indexData = null;896 // always clear the cache to make sure that we catch changes in geometry897 mpAreaCache.clear();898 super.endTest();899 956 } 957 958 private static String simplifySourceName(String source) { 959 if (source.endsWith(".mapcss")) // do we have others? 960 source = new File(source).getName(); 961 if (source.length() > 33) { 962 source = "..." + source.substring(source.length() - 30); 963 } 964 return source; 965 } 966 900 967 }
