1 | // License: GPL. See LICENSE file for details.
|
---|
2 | package org.openstreetmap.josm.data.validation.tests;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.util.Map;
|
---|
7 | import java.util.List;
|
---|
8 | import java.util.HashMap;
|
---|
9 | import java.util.HashSet;
|
---|
10 | import java.util.ArrayList;
|
---|
11 |
|
---|
12 |
|
---|
13 | import org.openstreetmap.josm.data.osm.Node;
|
---|
14 | import org.openstreetmap.josm.data.validation.Severity;
|
---|
15 | import org.openstreetmap.josm.data.validation.Test;
|
---|
16 | import org.openstreetmap.josm.data.validation.TestError;
|
---|
17 | import org.openstreetmap.josm.gui.progress.ProgressMonitor;
|
---|
18 |
|
---|
19 | public class NodesWithSameName extends Test {
|
---|
20 | protected static int SAME_NAME = 801;
|
---|
21 |
|
---|
22 | private Map<String, List<Node>> namesToNodes;
|
---|
23 |
|
---|
24 | public NodesWithSameName() {
|
---|
25 | super(tr("Nodes with same name"),
|
---|
26 | tr("This test finds nodes that have the same name (might be duplicates)."));
|
---|
27 | }
|
---|
28 |
|
---|
29 | @Override public void startTest(ProgressMonitor monitor) {
|
---|
30 | super.startTest(monitor);
|
---|
31 | namesToNodes = new HashMap<String, List<Node>>();
|
---|
32 | }
|
---|
33 |
|
---|
34 | @Override public void visit(Node n) {
|
---|
35 | if (!n.isUsable()) return;
|
---|
36 |
|
---|
37 | String name = n.get("name");
|
---|
38 | String sign = n.get("traffic_sign");
|
---|
39 | String highway = n.get("highway");
|
---|
40 | if (name == null
|
---|
41 | || (sign != null && sign.equals("city_limit"))
|
---|
42 | || (highway != null && highway.equals("bus_stop"))) {
|
---|
43 | return;
|
---|
44 | }
|
---|
45 |
|
---|
46 | List<Node> nodes = namesToNodes.get(name);
|
---|
47 | if (nodes == null)
|
---|
48 | namesToNodes.put(name, nodes = new ArrayList<Node>());
|
---|
49 |
|
---|
50 | nodes.add(n);
|
---|
51 | }
|
---|
52 |
|
---|
53 | @Override public void endTest() {
|
---|
54 | for (List<Node> nodes : namesToNodes.values()) {
|
---|
55 | if (nodes.size() > 1) {
|
---|
56 | // Report the same-name nodes, unless each has a unique ref=*.
|
---|
57 | HashSet<String> refs = new HashSet<String>();
|
---|
58 |
|
---|
59 | for (Node n : nodes) {
|
---|
60 | String ref = n.get("ref");
|
---|
61 | if (ref == null || !refs.add(ref)) {
|
---|
62 | errors.add(new TestError(this, Severity.OTHER,
|
---|
63 | tr("Nodes with same name"), SAME_NAME, nodes));
|
---|
64 | break;
|
---|
65 | }
|
---|
66 | }
|
---|
67 | }
|
---|
68 | }
|
---|
69 | super.endTest();
|
---|
70 | namesToNodes = null;
|
---|
71 | }
|
---|
72 | }
|
---|