diff --git a/src/org/openstreetmap/josm/data/validation/tests/Addresses.java b/src/org/openstreetmap/josm/data/validation/tests/Addresses.java
index 4f1fc1e50..387dd4601 100644
|
a
|
b
|
import java.util.Set;
|
| 19 | 19 | import java.util.stream.Collectors; |
| 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; |
| 24 | 27 | import org.openstreetmap.josm.data.coor.EastNorth; |
| … |
… |
import org.openstreetmap.josm.data.osm.Relation;
|
| 30 | 33 | import org.openstreetmap.josm.data.osm.RelationMember; |
| 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.tools.GBC; |
| 37 | 43 | import org.openstreetmap.josm.tools.Geometry; |
| 38 | 44 | import org.openstreetmap.josm.tools.Logging; |
| 39 | 45 | import org.openstreetmap.josm.tools.Pair; |
| … |
… |
public class Addresses extends Test {
|
| 70 | 76 | protected static final String ADDR_HOUSE_NAME = "addr:housename"; |
| 71 | 77 | protected static final String ADDR_POSTCODE = "addr:postcode"; |
| 72 | 78 | protected static final String ASSOCIATED_STREET = "associatedStreet"; |
| | 79 | protected static final String NAME = "name"; |
| 73 | 80 | // CHECKSTYLE.ON: SingleSpaceSeparator |
| 74 | 81 | |
| | 82 | private static final BooleanProperty PREF_INCLUDE_BLDG_POI = |
| | 83 | new BooleanProperty(ValidatorPrefHelper.PREFIX + "." + OpeningHourTest.class.getSimpleName() + "." + "includebldgpois", false); |
| | 84 | /* I18n: Label text for checkbox choosing to validate addresses for all types of objects, not just plain addresses */ |
| | 85 | private final JCheckBox checkboxIncludeBldgPOI = new JCheckBox(tr("Include POIs like amenities, offices, and buildings in duplicate address detection")); |
| | 86 | private boolean includeBldgAndPOI = false; |
| | 87 | |
| 75 | 88 | private Map<String, Collection<OsmPrimitive>> knownAddresses; |
| 76 | 89 | private Set<String> ignoredAddresses; |
| 77 | 90 | |
| … |
… |
public class Addresses extends Test {
|
| 79 | 92 | * Constructor |
| 80 | 93 | */ |
| 81 | 94 | public Addresses() { |
| | 95 | /* I18n: Label text for checkbox choosing to validate addresses */ |
| 82 | 96 | super(tr("Addresses"), tr("Checks for errors in addresses and associatedStreet relations.")); |
| | 97 | includeBldgAndPOI = PREF_INCLUDE_BLDG_POI.get(); |
| 83 | 98 | } |
| 84 | 99 | |
| 85 | 100 | protected List<Relation> getAndCheckAssociatedStreets(OsmPrimitive p) { |
| … |
… |
public class Addresses extends Test {
|
| 141 | 156 | * @param p OsmPrimitive that has an address |
| 142 | 157 | */ |
| 143 | 158 | private void collectAddress(OsmPrimitive p) { |
| 144 | | if (!isPOI(p)) { |
| | 159 | if (includeBldgAndPOI || !isPOI(p)) { |
| 145 | 160 | for (String simplifiedAddress : getSimplifiedAddresses(p)) { |
| 146 | 161 | if (!ignoredAddresses.contains(simplifiedAddress)) { |
| 147 | 162 | knownAddresses.computeIfAbsent(simplifiedAddress, x -> new ArrayList<>()).add(p); |
| … |
… |
public class Addresses extends Test {
|
| 154 | 169 | knownAddresses = new HashMap<>(); |
| 155 | 170 | ignoredAddresses = new HashSet<>(); |
| 156 | 171 | for (OsmPrimitive p : primitive.getDataSet().allNonDeletedPrimitives()) { |
| 157 | | if (p instanceof Node && p.hasKey(ADDR_UNIT, ADDR_FLATS)) { |
| | 172 | if ((includeBldgAndPOI || p instanceof Node) && p.hasKey(ADDR_UNIT, ADDR_FLATS)) { |
| 158 | 173 | for (OsmPrimitive r : p.getReferrers()) { |
| 159 | 174 | if (hasAddress(r)) { |
| 160 | 175 | // ignore addresses of buildings that are connected to addr:unit nodes |
| … |
… |
public class Addresses extends Test {
|
| 186 | 201 | if (knownAddresses == null) { |
| 187 | 202 | initAddressMap(p); |
| 188 | 203 | } |
| 189 | | if (!isPOI(p) && hasAddress(p)) { |
| | 204 | if ((includeBldgAndPOI || !isPOI(p)) && hasAddress(p)) { |
| 190 | 205 | List<TestError> result = new ArrayList<>(); |
| 191 | 206 | for (String simplifiedAddress : getSimplifiedAddresses(p)) { |
| 192 | 207 | if (!ignoredAddresses.contains(simplifiedAddress) && knownAddresses.containsKey(simplifiedAddress)) { |
| … |
… |
public class Addresses extends Test {
|
| 198 | 213 | Severity severityLevel; |
| 199 | 214 | String city1 = p.get(ADDR_CITY); |
| 200 | 215 | String city2 = p2.get(ADDR_CITY); |
| | 216 | String name1 = p.get(NAME); |
| | 217 | String name2 = p2.get(NAME); |
| 201 | 218 | double distance = getDistance(p, p2); |
| 202 | 219 | if (city1 != null && city2 != null) { |
| 203 | 220 | if (city1.equals(city2)) { |
| … |
… |
public class Addresses extends Test {
|
| 235 | 252 | } |
| 236 | 253 | } |
| 237 | 254 | } |
| | 255 | if (severityLevel == Severity.WARNING && name1 != name2) { |
| | 256 | // since multiple objects can exist at one address, a different name tag isn't very concerning |
| | 257 | severityLevel = Severity.OTHER; |
| | 258 | } |
| 238 | 259 | result.add(TestError.builder(this, severityLevel, DUPLICATE_HOUSE_NUMBER) |
| 239 | 260 | .message(tr("Duplicate house numbers"), marktr("''{0}'' ({1}m)"), simplifiedAddress, (int) distance) |
| 240 | 261 | .primitives(Arrays.asList(p, p2)).build()); |
| … |
… |
public class Addresses extends Test {
|
| 522 | 543 | return testError.getCode() == OBSOLETE_RELATION; |
| 523 | 544 | } |
| 524 | 545 | |
| | 546 | @Override |
| | 547 | public void addGui(JPanel testPanel) { |
| | 548 | super.addGui(testPanel); |
| | 549 | checkboxIncludeBldgPOI.setSelected(PREF_INCLUDE_BLDG_POI.get()); |
| | 550 | testPanel.add(checkboxIncludeBldgPOI, GBC.eol().insets(20, 0, 0, 0)); |
| | 551 | } |
| | 552 | |
| | 553 | @Override |
| | 554 | public boolean ok() { |
| | 555 | super.ok(); |
| | 556 | PREF_INCLUDE_BLDG_POI.put(checkboxIncludeBldgPOI.isSelected()); |
| | 557 | includeBldgAndPOI = PREF_INCLUDE_BLDG_POI.get(); |
| | 558 | return false; |
| | 559 | } |
| | 560 | |
| 525 | 561 | } |