Changeset 19170 in josm
- Timestamp:
- 2024-08-06T23:29:28+02:00 (4 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/validation/tests/TagChecker.java
r19080 r19170 39 39 import org.openstreetmap.josm.command.Command; 40 40 import org.openstreetmap.josm.command.SequenceCommand; 41 import org.openstreetmap.josm.data.coor.ILatLon; 41 42 import org.openstreetmap.josm.data.coor.LatLon; 42 43 import org.openstreetmap.josm.data.osm.AbstractPrimitive; 43 44 import org.openstreetmap.josm.data.osm.DataSet; 45 import org.openstreetmap.josm.data.osm.INode; 46 import org.openstreetmap.josm.data.osm.IPrimitive; 47 import org.openstreetmap.josm.data.osm.IRelation; 48 import org.openstreetmap.josm.data.osm.IWay; 44 49 import org.openstreetmap.josm.data.osm.Node; 45 50 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 806 811 private void tagCheckReal(TaggingPreset preset, OsmPrimitive p, LatLon center, RegionSpecific data) { 807 812 // First, check if we aren't in the region for the tag 808 if (latLonInRegions(center, data.regions()) == data.exclude_regions()) { 813 if (latLonInRegions(center, data.regions()) == data.exclude_regions() 814 // Check to ensure that no nodes are in the region if the center is not in the region 815 && !primitiveInRegions(p, data.regions(), data.exclude_regions())) { 809 816 final String key; 810 817 final String value; … … 840 847 841 848 /** 849 * Check if a primitive is in the specified regions 850 * @param primitive The primitive to recursively check 851 * @param regions The regions to look for 852 * @param excludeRegions Whether or not we are looking to exclude the regions (see {@link RegionSpecific#exclude_regions()}) 853 * @return {@code true} if the primitive is in a region that it should not be 854 */ 855 private static boolean primitiveInRegions(IPrimitive primitive, Collection<String> regions, boolean excludeRegions) { 856 if (primitive instanceof INode) { 857 return latLonInRegions((INode) primitive, regions) == excludeRegions; 858 } else if (primitive instanceof IWay) { 859 return ((IWay<?>) primitive).getNodes().stream().anyMatch(n -> primitiveInRegions(n, regions, excludeRegions)); 860 } else if (primitive instanceof IRelation) { 861 return ((IRelation<?>) primitive).getMemberPrimitivesList().stream().anyMatch(p -> primitiveInRegions(p, regions, excludeRegions)); 862 } 863 throw new IllegalArgumentException("Unknown primitive type: " + primitive); 864 } 865 866 /** 842 867 * Check if the specified latlon is inside any of the specified regions 843 868 * @param latLon The {@link LatLon} to check … … 845 870 * @return {@code true} if the coordinate is inside any of the regions 846 871 */ 847 private static boolean latLonInRegions( LatLon latLon, Collection<String> regions) {872 private static boolean latLonInRegions(ILatLon latLon, Collection<String> regions) { 848 873 if (regions != null) { 849 874 for (String region : regions) { 850 if (Territories.isIso3166Code(region, latLon )) {875 if (Territories.isIso3166Code(region, latLon instanceof LatLon ? (LatLon) latLon : new LatLon(latLon))) { 851 876 return true; 852 877 }
Note:
See TracChangeset
for help on using the changeset viewer.