| | 306 | |
| | 307 | private void testDifferentLayers(Node connection) { |
| | 308 | List<Way> ways = connection.getParentWays(); |
| | 309 | ways.removeIf(w -> !w.hasTag("highway") || w.hasTag("highway", "steps")); |
| | 310 | if (ways.size() < 2 || ways.stream().noneMatch(w -> w.hasKey("layer"))) |
| | 311 | return; |
| | 312 | // check if connection has ways with different layers |
| | 313 | Map<String, List<Way>> layerCount = new HashMap<>(); |
| | 314 | for (Way w : ways) { |
| | 315 | String layer = w.get("layer"); |
| | 316 | if (layer == null) |
| | 317 | layer = "0"; |
| | 318 | layerCount.computeIfAbsent(layer, k-> new ArrayList<>()).add(w); |
| | 319 | } |
| | 320 | if (layerCount.size() == 1) |
| | 321 | return; // all on the same layer |
| | 322 | |
| | 323 | for (Entry<String, List<Way>> entry : layerCount.entrySet()) { |
| | 324 | if ("0".equals(entry.getKey())) |
| | 325 | continue; |
| | 326 | if (checkLayer(connection, entry.getValue())) { |
| | 327 | errors.add(TestError.builder(this, Severity.WARNING, DIFFERENT_LAYERS) |
| | 328 | .message(tr("Node connects highways on different layers")) |
| | 329 | .primitives(connection) |
| | 330 | .build()); |
| | 331 | return; |
| | 332 | } |
| | 333 | } |
| | 334 | } |
| | 335 | |
| | 336 | /** |
| | 337 | * Check if there are at least two neighbouring nodes on the given ways. |
| | 338 | * If so, the connection node can be considered to be at a specific layer, else it marks the end of such a layer |
| | 339 | * @param connection the connection node |
| | 340 | * @param ways the ways with the same layer attribute connected to that node |
| | 341 | * @return true if the node can be considered to be at a specific layer |
| | 342 | */ |
| | 343 | private static boolean checkLayer(Node connection, List<Way> ways) { |
| | 344 | int count = 0; |
| | 345 | for (Way w : ways) { |
| | 346 | if (!w.isFirstLastNode(connection)) |
| | 347 | return true; // connection node has two neighbouring nodes |
| | 348 | count++; |
| | 349 | } |
| | 350 | return count > 1; |
| | 351 | } |