source: josm/trunk/src/org/openstreetmap/josm/data/validation/tests/SelfIntersectingWay.java@ 11129

Last change on this file since 11129 was 11129, checked in by simon04, 8 years ago

fix #13799 - Use builder pattern for TestError

  • Property svn:eol-style set to native
File size: 1.4 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.Way;
11import org.openstreetmap.josm.data.validation.Severity;
12import org.openstreetmap.josm.data.validation.Test;
13import org.openstreetmap.josm.data.validation.TestError;
14
15/**
16 * Checks for self-intersecting ways.
17 */
18public class SelfIntersectingWay extends Test {
19
20 protected static final int SELF_INTERSECT = 401;
21
22 /**
23 * Constructs a new {@code SelfIntersectingWay} test.
24 */
25 public SelfIntersectingWay() {
26 super(tr("Self-intersecting ways"),
27 tr("This test checks for ways " +
28 "that contain some of their nodes more than once."));
29 }
30
31 @Override
32 public void visit(Way w) {
33 Set<Node> nodes = new HashSet<>();
34
35 for (int i = 1; i < w.getNodesCount() - 1; i++) {
36 Node n = w.getNode(i);
37 if (nodes.contains(n)) {
38 errors.add(TestError.builder(this, Severity.WARNING, SELF_INTERSECT)
39 .message(tr("Self-intersecting ways"))
40 .primitives(w)
41 .highlight(n)
42 .build());
43 break;
44 } else {
45 nodes.add(n);
46 }
47 }
48 }
49}
Note: See TracBrowser for help on using the repository browser.