- Timestamp:
- 2023-12-20T20:03:45+01:00 (11 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/validation/tests/Addresses.java
r18871 r18922 20 20 import java.util.stream.Stream; 21 21 22 import javax.swing.JCheckBox; 23 import javax.swing.JPanel; 24 22 25 import org.openstreetmap.josm.command.Command; 23 26 import org.openstreetmap.josm.command.DeleteCommand; … … 31 34 import org.openstreetmap.josm.data.osm.TagMap; 32 35 import org.openstreetmap.josm.data.osm.Way; 36 import org.openstreetmap.josm.data.preferences.BooleanProperty; 33 37 import org.openstreetmap.josm.data.preferences.DoubleProperty; 38 import org.openstreetmap.josm.data.preferences.sources.ValidatorPrefHelper; 34 39 import org.openstreetmap.josm.data.validation.Severity; 35 40 import org.openstreetmap.josm.data.validation.Test; 36 41 import org.openstreetmap.josm.data.validation.TestError; 42 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 43 import org.openstreetmap.josm.tools.GBC; 37 44 import org.openstreetmap.josm.tools.Geometry; 38 45 import org.openstreetmap.josm.tools.Logging; … … 71 78 protected static final String ADDR_POSTCODE = "addr:postcode"; 72 79 protected static final String ASSOCIATED_STREET = "associatedStreet"; 80 protected static final String NAME_TAG = "name"; 81 private static final String HOUSE = "house"; 82 private static final String STREET = "street"; 73 83 // CHECKSTYLE.ON: SingleSpaceSeparator 84 85 private static final BooleanProperty PREF_INCLUDE_BLDG_POI = 86 new BooleanProperty(ValidatorPrefHelper.PREFIX + "." + OpeningHourTest.class.getSimpleName() + "." + "includebuildingpois", false); 87 private final JCheckBox checkboxIncludeBldgPOI = new JCheckBox( 88 /* I18n: Label text for checkbox choosing to validate addresses for all types of objects, not just plain addresses */ 89 tr("Include POIs like amenities, offices, and buildings in duplicate address detection")); 90 private boolean includeBldgAndPOI; 74 91 75 92 private Map<String, Collection<OsmPrimitive>> knownAddresses; … … 80 97 */ 81 98 public Addresses() { 99 /* I18n: Label text for checkbox choosing to validate addresses */ 82 100 super(tr("Addresses"), tr("Checks for errors in addresses and associatedStreet relations.")); 83 101 } … … 142 160 */ 143 161 private void collectAddress(OsmPrimitive p) { 144 if ( !isPOI(p)) {162 if (includeBldgAndPOI || !isPOI(p)) { 145 163 for (String simplifiedAddress : getSimplifiedAddresses(p)) { 146 164 if (!ignoredAddresses.contains(simplifiedAddress)) { … … 155 173 ignoredAddresses = new HashSet<>(); 156 174 for (OsmPrimitive p : primitive.getDataSet().allNonDeletedPrimitives()) { 157 if ( p instanceof Node&& p.hasKey(ADDR_UNIT, ADDR_FLATS)) {175 if ((includeBldgAndPOI || p instanceof Node) && p.hasKey(ADDR_UNIT, ADDR_FLATS)) { 158 176 for (OsmPrimitive r : p.getReferrers()) { 159 177 if (hasAddress(r)) { … … 177 195 178 196 @Override 197 public void startTest(ProgressMonitor progressMonitor) { 198 super.startTest(progressMonitor); 199 this.includeBldgAndPOI = PREF_INCLUDE_BLDG_POI.get(); 200 } 201 202 @Override 179 203 public void endTest() { 180 204 knownAddresses = null; … … 187 211 initAddressMap(p); 188 212 } 189 if ( !isPOI(p) && hasAddress(p)) {213 if ((includeBldgAndPOI || !isPOI(p)) && hasAddress(p)) { 190 214 List<TestError> result = new ArrayList<>(); 191 215 for (String simplifiedAddress : getSimplifiedAddresses(p)) { … … 199 223 String city1 = p.get(ADDR_CITY); 200 224 String city2 = p2.get(ADDR_CITY); 225 String name1 = p.get(NAME_TAG); 226 String name2 = p2.get(NAME_TAG); 201 227 double distance = getDistance(p, p2); 202 228 if (city1 != null && city2 != null) { … … 236 262 } 237 263 } 264 if (severityLevel == Severity.WARNING && !Objects.equals(name1, name2)) { 265 // since multiple objects can exist at one address, a different name tag isn't very concerning 266 severityLevel = Severity.OTHER; 267 } 238 268 result.add(TestError.builder(this, severityLevel, DUPLICATE_HOUSE_NUMBER) 239 269 .message(tr("Duplicate house numbers"), marktr("''{0}'' ({1}m)"), simplifiedAddress, (int) distance) … … 302 332 String role = m.getRole(); 303 333 OsmPrimitive p = m.getMember(); 304 if ( "house".equals(role)) {334 if (HOUSE.equals(role)) { 305 335 houses.add(p); 306 336 String number = p.get(ADDR_HOUSE_NUMBER); … … 316 346 wrongStreetNames.add(p); 317 347 } 318 } else if ( "street".equals(role)) {348 } else if (STREET.equals(role)) { 319 349 if (p instanceof Way) { 320 350 street.add((Way) p); … … 457 487 if ("".equals(role)) { 458 488 if (m.isWay() && m.getMember().hasKey("highway")) { 459 role = "street";489 role = STREET; 460 490 } else if (m.getMember().hasTag("building")) 461 role = "house";491 role = HOUSE; 462 492 } 463 493 switch (role) { 464 case "house":494 case HOUSE: 465 495 case "addr:houselink": 466 496 case "address": … … 472 502 } 473 503 break; 474 case "street":504 case STREET: 475 505 if (!m.getMember().hasTag("name") && r.hasTag("name")) 476 506 return; … … 523 553 } 524 554 555 @Override 556 public void addGui(JPanel testPanel) { 557 super.addGui(testPanel); 558 checkboxIncludeBldgPOI.setSelected(PREF_INCLUDE_BLDG_POI.get()); 559 testPanel.add(checkboxIncludeBldgPOI, GBC.eol().insets(20, 0, 0, 0)); 560 } 561 562 @Override 563 public boolean ok() { 564 super.ok(); 565 PREF_INCLUDE_BLDG_POI.put(checkboxIncludeBldgPOI.isSelected()); 566 includeBldgAndPOI = PREF_INCLUDE_BLDG_POI.get(); 567 return false; 568 } 569 525 570 }
Note:
See TracChangeset
for help on using the changeset viewer.