-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #23708 Only check restrictions with subtypes #68
Conversation
The PublicTransportMendRelationAction.isRestricted method checks against a hardcoded list of vehicle types: ["restriction", "restriction:bus", "restriction:trolleybus", ...] However, it tries to pull out the subtype and fails on that first entry, since there is no subtype in "restriction".
I don't see a need to create a new array. A simple check for the length should be enough. Something like |
@michaelabon Thanks for the pull request! I think an elegant solution could be something along the lines of Also: Instead of assinging |
Responding to feedback that there was too much unnecessary complexity introduced by creating a `restrictionTypes` array based off of the `restrictions` array.
@GerdP @floscher Thanks for the feedback. I've reined in the changes to just a length check. I've removed the
@floscher I don't know quite see how or where that would fit in the loop. Can you be a bit more explicit, please? |
String routeValue = relation.get("route"); | ||
for (String s : restrictions) { | ||
if (s.length() <= 12) | ||
continue; | ||
String sub = s.substring(12); | ||
if (routeValue.equals(sub) && rel.hasTag("type", s)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@michaelabon Sure, I was a bit in a rush earlier. This would be how it could be written:
String routeValue = relation.get("route"); | |
for (String s : restrictions) { | |
if (s.length() <= 12) | |
continue; | |
String sub = s.substring(12); | |
if (routeValue.equals(sub) && rel.hasTag("type", s)) | |
final String routeValue = Optional.ofNullable(relation.get("route")).map(it -> "restriction:" + it).orElse(""); | |
for (String s : restrictions) { | |
if (routeValue.equals(s) && rel.hasTag("type", s)) |
So previously the prefix restriction:
was removed from s
and then compared with routeValue
.
But now we prepend the prefix restriction:
to routeValue
and then compare it with s
.
...eetmap/josm/plugins/pt_assistant/actions/mendrelation/PublicTransportMendRelationAction.java
Outdated
Show resolved
Hide resolved
To test this, I've been using the That session has a newly-created relation named TEST TEST TEST with a “start” way and an ”end” way for a bus route. That fulfills the first two steps in my Steps to Reproduce section in #23708. |
Fixes JOSM #23708.
The
PublicTransportMendRelationAction.isRestricted
method checks against a hardcoded list of vehicle types:However, it tries to pull out the subtype and fails on that first entry, since there is no subtype in
"restriction"
.This change will filter the list of restrictions for only those with subtypes.