From dfcf6448057a7936e1fb5fac16fc915a7f273af9 Mon Sep 17 00:00:00 2001 From: Michael Abon Date: Tue, 4 Jun 2024 15:40:21 -0500 Subject: [PATCH] Use Optional.ofNullable to avoid string length checks --- .../mendrelation/PublicTransportMendRelationAction.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/openstreetmap/josm/plugins/pt_assistant/actions/mendrelation/PublicTransportMendRelationAction.java b/src/main/java/org/openstreetmap/josm/plugins/pt_assistant/actions/mendrelation/PublicTransportMendRelationAction.java index e8a794a0..09f9bace 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/pt_assistant/actions/mendrelation/PublicTransportMendRelationAction.java +++ b/src/main/java/org/openstreetmap/josm/plugins/pt_assistant/actions/mendrelation/PublicTransportMendRelationAction.java @@ -1120,14 +1120,9 @@ boolean isRestricted(Way currentWay, Way previousWay, Node commonNode) { else if (rel.hasTag("type", "restriction") && rel.hasKey("restriction")) return false; else { - String routeValue = relation.get("route"); + final String routeValue = Optional.ofNullable(relation.get("route")).map(it -> "restriction:" + it).orElse(""); for (String s : restrictions) { - if (s.length() <= 12) - continue; - String sub = s.substring(12); - if (routeValue.equals(sub) && rel.hasTag("type", s)) - return false; - else if (routeValue.equals(sub) && rel.hasKey("restriction:" + sub)) + if (routeValue.equals(s) && (rel.hasTag("type", s) || rel.hasKey(s))) return false; } return true;