source: josm/trunk/src/org/openstreetmap/josm/data/validation/tests/UnclosedWays.java@ 6240

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

Sonar - fix some issues in data.validation.tests

  • Property svn:eol-style set to native
File size: 3.5 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.marktr;
5import static org.openstreetmap.josm.tools.I18n.tr;
6
7import java.text.MessageFormat;
8import java.util.Arrays;
9
10import org.openstreetmap.josm.data.osm.OsmPrimitive;
11import org.openstreetmap.josm.data.osm.OsmUtils;
12import org.openstreetmap.josm.data.osm.Relation;
13import org.openstreetmap.josm.data.osm.Way;
14import org.openstreetmap.josm.data.validation.Severity;
15import org.openstreetmap.josm.data.validation.Test;
16import org.openstreetmap.josm.data.validation.TestError;
17
18/**
19 * Check area type ways for errors
20 *
21 * @author stoecker
22 */
23public class UnclosedWays extends Test {
24
25 /**
26 * Constructor
27 */
28 public UnclosedWays() {
29 super(tr("Unclosed Ways"), tr("This tests if ways which should be circular are closed."));
30 }
31
32 private String type;
33 private String etype;
34 private int mode;
35
36 public void set(int m, String text, String desc) {
37 etype = MessageFormat.format(text, desc);
38 type = tr(text, tr(desc));
39 mode = m;
40 }
41
42 public void set(int m, String text) {
43 etype = text;
44 type = tr(text);
45 mode = m;
46 }
47
48 @Override
49 public void visit(Way w) {
50 String test;
51 type = etype = null;
52 mode = 0;
53
54 if (!w.isUsable())
55 return;
56
57 test = w.get("natural");
58 if (test != null && !"coastline".equals(test) && !"cliff".equals(test) && !"tree_row".equals(test)) {
59 set(1101, marktr("natural type {0}"), test);
60 }
61 test = w.get("landuse");
62 if (test != null) {
63 set(1102, marktr("landuse type {0}"), test);
64 }
65 test = w.get("amenities");
66 if (test != null) {
67 set(1103, marktr("amenities type {0}"), test);
68 }
69 test = w.get("sport");
70 if (test != null && !test.equals("water_slide")) {
71 set(1104, marktr("sport type {0}"), test);
72 }
73 test = w.get("tourism");
74 if (test != null) {
75 set(1105, marktr("tourism type {0}"), test);
76 }
77 test = w.get("shop");
78 if (test != null) {
79 set(1106, marktr("shop type {0}"), test);
80 }
81 test = w.get("leisure");
82 if (test != null && !"track".contains(test)) {
83 set(1107, marktr("leisure type {0}"), test);
84 }
85 test = w.get("waterway");
86 if ("riverbank".equals(test)) {
87 set(1108, marktr("waterway type {0}"), test);
88 }
89 Boolean btest = OsmUtils.getOsmBoolean(w.get("building"));
90 if (btest != null && btest) {
91 set(1120, marktr("building"));
92 }
93 btest = OsmUtils.getOsmBoolean(w.get("area"));
94 if (btest != null && btest) {
95 set(1130, marktr("area"));
96 }
97
98 if (type != null && !w.isArea()) {
99 for (OsmPrimitive parent: w.getReferrers()) {
100 if (parent instanceof Relation && ((Relation)parent).isMultipolygon())
101 return;
102 }
103
104 errors.add(new TestError(this, Severity.WARNING, tr("Unclosed way"),
105 type, etype, mode,
106 Arrays.asList(w),
107 // The important parts of an unclosed way are the first and
108 // the last node which should be connected, therefore we highlight them
109 Arrays.asList(w.firstNode(), w.lastNode())));
110 }
111 }
112}
Note: See TracBrowser for help on using the repository browser.