Ticket #24280: PATCH_no_entry_validator.diff
| File PATCH_no_entry_validator.diff, 8.1 KB (added by , 11 months ago) |
|---|
-
src/org/openstreetmap/josm/data/validation/tests/TurnrestrictionTest.java
21 21 22 22 /** 23 23 * Checks if turn restrictions are valid 24 * 24 25 * @since 3669 25 26 */ 26 27 public class TurnrestrictionTest extends Test { … … 86 87 return; 87 88 } 88 89 89 Way fromWay = null;90 List<Way> fromWays = new ArrayList<>(); 90 91 Way toWay = null; 91 92 List<OsmPrimitive> via = new ArrayList<>(); 92 93 93 boolean morefrom = false;94 94 boolean moreto = false; 95 95 boolean morevia = false; 96 96 boolean mixvia = false; … … 111 111 112 112 switch (m.getRole()) { 113 113 case "from": 114 if (fromWay != null) { 115 morefrom = true; 116 } else { 117 fromWay = w; 118 } 114 fromWays.add(w); 119 115 break; 120 116 case "to": 121 117 if (toWay != null) { … … 128 124 if (!via.isEmpty() && via.get(0) instanceof Node) { 129 125 mixvia = true; 130 126 } else { 131 via.add(w); 127 via.add(w); 132 128 } 133 129 break; 134 130 default: … … 165 161 .build()); 166 162 } 167 163 } 168 if (morefrom) { 169 errors.add(TestError.builder(this, Severity.ERROR, MORE_FROM) 170 .message(tr("More than one \"from\" way found")) 171 .primitives(r) 172 .build()); 173 return; 164 if (fromWays.size() > 1) { 165 if (!r.hasTag("restriction", "no_entry")) { 166 167 errors.add(TestError.builder(this, Severity.ERROR, MORE_FROM) 168 .message(tr("More than one \"from\" way found")) 169 .primitives(r) 170 .build()); 171 return; 172 } 174 173 } 175 174 if (moreto) { 176 175 errors.add(TestError.builder(this, Severity.ERROR, MORE_TO) … … 194 193 return; 195 194 } 196 195 197 if (fromWay == null) {196 if (fromWays.isEmpty()) { 198 197 errors.add(TestError.builder(this, Severity.ERROR, NO_FROM) 199 198 .message(tr("No \"from\" way found")) 200 199 .primitives(r) 201 200 .build()); 202 201 return; 203 } else if (fromWay.isClosed()) { 204 errors.add(TestError.builder(this, Severity.ERROR, FROM_CLOSED_WAY) 205 .message(tr("\"from\" way is a closed way")) 206 .primitives(r) 207 .highlight(fromWay) 208 .build()); 209 return; 210 } 202 } else 211 203 204 for (Way fromWay : fromWays) { 205 if (fromWay.isClosed()) { 206 errors.add(TestError.builder(this, Severity.ERROR, FROM_CLOSED_WAY) 207 .message(tr("\"from\" way is a closed way")) 208 .primitives(r) 209 .highlight(fromWay) 210 .build()); 211 return; 212 } 213 } 214 212 215 if (toWay == null) { 213 216 errors.add(TestError.builder(this, Severity.ERROR, NO_TO) 214 217 .message(tr("No \"to\" way found")) … … 223 226 .build()); 224 227 return; 225 228 } 226 if (fromWay.equals(toWay)) { 227 Severity severity = r.hasTag("restriction", "no_u_turn") ? Severity.OTHER : Severity.WARNING; 228 errors.add(TestError.builder(this, severity, FROM_EQUALS_TO) 229 .message(tr("\"from\" way equals \"to\" way")) 230 .primitives(r) 231 .build()); 229 for (Way fromWay : fromWays) { 230 231 if (fromWay.equals(toWay)) { 232 Severity severity = r.hasTag("restriction", "no_u_turn") ? Severity.OTHER : Severity.WARNING; 233 errors.add(TestError.builder(this, severity, FROM_EQUALS_TO) 234 .message(tr("\"from\" way equals \"to\" way")) 235 .primitives(r) 236 .build()); 237 } 232 238 } 233 239 if (via.isEmpty()) { 234 240 errors.add(TestError.builder(this, Severity.ERROR, NO_VIA) … … 248 254 .build()); 249 255 return; 250 256 } 251 if (isFullOneway(fromWay) && viaNode.equals(fromWay.firstNode(true))) { 252 errors.add(TestError.builder(this, Severity.WARNING, SUPERFLUOUS) 257 if (fromWays.size() == 1){ 258 Way fromWay = fromWays.get(0); 259 if (isFullOneway(fromWay) && viaNode.equals(fromWay.firstNode(true))) { 260 errors.add(TestError.builder(this, Severity.WARNING, SUPERFLUOUS) 253 261 .message(tr("Superfluous turn restriction as \"from\" way is oneway")) 254 262 .primitives(r) 255 263 .highlight(fromWay) 256 264 .build()); 257 return; 265 return; 266 } 258 267 } 259 if (!fromWay.isFirstLastNode(viaNode)) { 260 errors.add(TestError.builder(this, Severity.WARNING, FROM_VIA_NODE) 261 .message(tr("The \"from\" way does not start or end at a \"via\" node.")) 262 .primitives(r, fromWay, viaNode) 263 .highlight(fromWay, viaNode) 264 .build()); 268 269 for (Way fromWay : fromWays) { 270 271 if (!fromWay.isFirstLastNode(viaNode)) { 272 errors.add(TestError.builder(this, Severity.WARNING, FROM_VIA_NODE) 273 .message(tr("The \"from\" way does not start or end at a \"via\" node.")) 274 .primitives(r, fromWay, viaNode) 275 .highlight(fromWay, viaNode) 276 .build()); 277 } 265 278 } 266 279 if (!toWay.isFirstLastNode(viaNode)) { 267 280 errors.add(TestError.builder(this, Severity.WARNING, TO_VIA_NODE) … … 279 292 .build()); 280 293 return; 281 294 } 282 if (isFullOneway(fromWay) && ((Way) via.get(0)).isFirstLastNode(fromWay.firstNode(true))) { 283 errors.add(TestError.builder(this, Severity.WARNING, SUPERFLUOUS) 284 .message(tr("Superfluous turn restriction as \"from\" way is oneway")) 285 .primitives(r) 286 .highlight(fromWay) 287 .build()); 288 return; 295 if (fromWays.size() == 1) { 296 Way fromWay = fromWays.get(0); 297 if (isFullOneway(fromWay) && ((Way) via.get(0)).isFirstLastNode(fromWay.firstNode(true))) { 298 errors.add(TestError.builder(this, Severity.WARNING, SUPERFLUOUS) 299 .message(tr("Superfluous turn restriction as \"from\" way is oneway")) 300 .primitives(r) 301 .highlight(fromWay) 302 .build()); 303 return; 304 } 289 305 } 290 306 // check if consecutive ways are connected: from/via[0], via[i-1]/via[i], via[last]/to 291 checkIfConnected(r, fromWay, (Way) via.get(0), 292 tr("The \"from\" and the first \"via\" way are not connected."), FROM_VIA_WAY); 307 for (Way fromWay : fromWays) { 308 checkIfConnected(r, fromWay, (Way) via.get(0), 309 tr("The \"from\" and the first \"via\" way are not connected."), FROM_VIA_WAY); 310 } 293 311 if (via.size() > 1) { 294 312 for (int i = 1; i < via.size(); i++) { 295 313 Way previous = (Way) via.get(i - 1);
