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

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

add validator plugin to josm core. Original author: Francisco R. Santos (frsantos); major contributions by bilbo, daeron, delta_foxtrot, imi, jttt, jrreid, gabriel, guggis, pieren, rrankin, skela, stoecker, stotz and others

  • Property svn:eol-style set to native
File size: 1.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.HashSet;
7import java.util.Arrays;
8
9import org.openstreetmap.josm.data.osm.Way;
10import org.openstreetmap.josm.data.osm.Node;
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 protected static int SELF_INTERSECT = 401;
20
21 public SelfIntersectingWay() {
22 super(tr("Self-intersecting ways"),
23 tr("This test checks for ways " +
24 "that contain some of their nodes more than once."));
25 }
26
27 @Override public void visit(Way w) {
28 HashSet<Node> nodes = new HashSet<Node>();
29
30 for (int i = 1; i < w.getNodesCount() - 1; i++) {
31 Node n = w.getNode(i);
32 if (nodes.contains(n)) {
33 errors.add(new TestError(this,
34 Severity.WARNING, tr("Self-intersecting ways"), SELF_INTERSECT,
35 Arrays.asList(w), Arrays.asList(n)));
36 break;
37 } else {
38 nodes.add(n);
39 }
40 }
41 }
42}
Note: See TracBrowser for help on using the repository browser.