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

Last change on this file since 7308 was 7005, checked in by Don-vip, 10 years ago

see #8465 - use diamond operator where applicable

  • Property svn:eol-style set to native
File size: 1.4 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.Arrays;
7import java.util.HashSet;
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 public void visit(Way w) {
32 HashSet<Node> nodes = new HashSet<>();
33
34 for (int i = 1; i < w.getNodesCount() - 1; i++) {
35 Node n = w.getNode(i);
36 if (nodes.contains(n)) {
37 errors.add(new TestError(this,
38 Severity.WARNING, tr("Self-intersecting ways"), SELF_INTERSECT,
39 Arrays.asList(w), Arrays.asList(n)));
40 break;
41 } else {
42 nodes.add(n);
43 }
44 }
45 }
46}
Note: See TracBrowser for help on using the repository browser.