1 | // License: GPL. See LICENSE file for details.
|
---|
2 | package org.openstreetmap.josm.data.validation.tests;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.util.HashSet;
|
---|
7 | import java.util.Arrays;
|
---|
8 |
|
---|
9 | import org.openstreetmap.josm.data.osm.Way;
|
---|
10 | import org.openstreetmap.josm.data.osm.Node;
|
---|
11 | import org.openstreetmap.josm.data.validation.Severity;
|
---|
12 | import org.openstreetmap.josm.data.validation.Test;
|
---|
13 | import org.openstreetmap.josm.data.validation.TestError;
|
---|
14 |
|
---|
15 | /**
|
---|
16 | * Checks for self-intersecting ways.
|
---|
17 | */
|
---|
18 | public class SelfIntersectingWay extends Test {
|
---|
19 |
|
---|
20 | protected static int SELF_INTERSECT = 401;
|
---|
21 |
|
---|
22 | public SelfIntersectingWay() {
|
---|
23 | super(tr("Self-intersecting ways"),
|
---|
24 | tr("This test checks for ways " +
|
---|
25 | "that contain some of their nodes more than once."));
|
---|
26 | }
|
---|
27 |
|
---|
28 | @Override public void visit(Way w) {
|
---|
29 | HashSet<Node> nodes = new HashSet<Node>();
|
---|
30 |
|
---|
31 | for (int i = 1; i < w.getNodesCount() - 1; i++) {
|
---|
32 | Node n = w.getNode(i);
|
---|
33 | if (nodes.contains(n)) {
|
---|
34 | errors.add(new TestError(this,
|
---|
35 | Severity.WARNING, tr("Self-intersecting ways"), SELF_INTERSECT,
|
---|
36 | Arrays.asList(w), Arrays.asList(n)));
|
---|
37 | break;
|
---|
38 | } else {
|
---|
39 | nodes.add(n);
|
---|
40 | }
|
---|
41 | }
|
---|
42 | }
|
---|
43 | }
|
---|