source: josm/trunk/src/org/openstreetmap/josm/data/validation/tests/NodesWithSameName.java@ 3715

Last change on this file since 3715 was 3671, checked in by bastiK, 13 years ago

adapt coding style (to some degree); there shouldn't be any semantic changes in this commit

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