source: josm/trunk/src/org/openstreetmap/josm/data/validation/tests/NodesDuplicatingWayTags.java@ 6386

Last change on this file since 6386 was 6241, checked in by Don-vip, 11 years ago

fix more warnings/javadoc in data.validation.tests

File size: 2.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.validation.tests;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.util.HashSet;
7import java.util.Set;
8
9import org.openstreetmap.josm.data.osm.Node;
10import org.openstreetmap.josm.data.osm.OsmPrimitive;
11import org.openstreetmap.josm.data.osm.Way;
12import org.openstreetmap.josm.data.validation.Severity;
13import org.openstreetmap.josm.data.validation.Test;
14import org.openstreetmap.josm.data.validation.TestError;
15
16/**
17 * Warn when a node has the same tags as its parent way. The check is rather
18 * conservative: it warns only when the tags are identical and important (i.e.,
19 * no warning for a way and a node that only have a "source=PGS" tag).
20 * <p>
21 * See JOSM ticket #7639 for the original request.
22 *
23 * @author Mrwojo
24 */
25public class NodesDuplicatingWayTags extends Test {
26
27 protected static final int NODE_DUPING_PARENT_WAY_TAGS = 2401;
28
29 /**
30 * Constructs a new {@code NodesDuplicatingWayTags} test.
31 */
32 public NodesDuplicatingWayTags() {
33 super(tr("Nodes duplicating way tags"),
34 tr("Checks for nodes that have the same tags as their parent way."));
35 }
36
37 @Override
38 public void visit(Way way) {
39 // isTagged represents interesting tags (not "source", "created_by", ...)
40 if (!way.isUsable() || !way.isTagged())
41 return;
42
43 // Use a set so you don't report the same node of an area/loop more than once.
44 Set<OsmPrimitive> dupedWayTags = new HashSet<OsmPrimitive>();
45
46 // Check for nodes in the way that have tags identical to the way's tags.
47 for (Node node : way.getNodes()) {
48 if (way.hasSameTags(node)) {
49 dupedWayTags.add(node);
50 }
51 }
52
53 if (!dupedWayTags.isEmpty()) {
54 // Add the way for the warning.
55 dupedWayTags.add(way);
56
57 errors.add(new TestError(this, Severity.WARNING, tr("Nodes duplicating parent way tags"),
58 NODE_DUPING_PARENT_WAY_TAGS, dupedWayTags));
59 }
60 }
61}
Note: See TracBrowser for help on using the repository browser.