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

Last change on this file since 3671 was 3671, checked in by bastiK, 15 years ago

adapt coding style (to some degree); there shouldn't be any semantic changes in this commit

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