Skip to content

Commit

Permalink
Remove legacy bike access mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed Nov 12, 2024
1 parent 237cf26 commit 2f0ccd8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,64 +5,23 @@
import org.opentripplanner.transit.model.network.BikeAccess;

/**
* Model bike access for GTFS trips.
* <p>
* The GTFS bike extensions is originally discussed at: https://groups.google.com/d/msg/gtfs-changes/QqaGOuNmG7o/xyqORy-T4y0J
* <p>
* It proposes "route_bikes_allowed" in routes.txt and "trip_bikes_allowed" in trips.txt with the
* following semantics:
* <p>
* 2: bikes allowed<br> 1: no bikes allowed<br> 0: no information (same as field omitted)<br>
* <p>
* The values in trips.txt override the values in routes.txt.
* <p>
* An alternative proposal is discussed in: https://groups.google.com/d/msg/gtfs-changes/rEiSeKNc4cs/gTTnQ_yXtPgJ
* <p>
* Here, the field "bikes_allowed" is used in both routes.txt and trip.txt with the following
* semantics:
* <p>
* 2: no bikes allowed<br> 1: bikes allowed<br> 0: no information (same as field omitted)<br>
* <p>
* Here, the 0,1,2 semantics have been changed to match the convention used in the
* "wheelchair_accessible" field in trips.txt.
* <p>
* A number of feeds are still using the original proposal and a number of feeds have been updated
* to use the new proposal. For now, we support both, using "bikes_allowed" if specified and then
* "trip_bikes_allowed".
* Model bike access for GTFS trips by using the bikes_allowed fields from route and trip.
*/
class BikeAccessMapper {

public static BikeAccess mapForTrip(Trip rhs) {
//noinspection deprecation
return mapValues(rhs.getBikesAllowed(), rhs.getTripBikesAllowed());
return mapValues(rhs.getBikesAllowed());
}

public static BikeAccess mapForRoute(Route rhs) {
//noinspection deprecation
return mapValues(rhs.getBikesAllowed(), rhs.getRouteBikesAllowed());
return mapValues(rhs.getBikesAllowed());
}

private static BikeAccess mapValues(int bikesAllowed, int legacyBikesAllowed) {
if (bikesAllowed != 0) {
switch (bikesAllowed) {
case 1:
return BikeAccess.ALLOWED;
case 2:
return BikeAccess.NOT_ALLOWED;
default:
return BikeAccess.UNKNOWN;
}
} else if (legacyBikesAllowed != 0) {
switch (legacyBikesAllowed) {
case 1:
return BikeAccess.NOT_ALLOWED;
case 2:
return BikeAccess.ALLOWED;
default:
return BikeAccess.UNKNOWN;
}
}

return BikeAccess.UNKNOWN;
private static BikeAccess mapValues(int bikesAllowed) {
return switch (bikesAllowed) {
case 1 -> BikeAccess.ALLOWED;
case 2 -> BikeAccess.NOT_ALLOWED;
default -> BikeAccess.UNKNOWN;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ public class BikeAccessMapperTest {

private static final int BIKES_ALLOWED = 1;
private static final int BIKES_NOT_ALLOWED = 2;
private static final int TRIP_BIKES_ALLOWED = 2;
private static final int TRIP_BIKES_NOT_ALLOWED = 1;
private static final int ROUTE_BIKES_ALLOWED = 2;
private static final int ROUTE_BIKES_NOT_ALLOWED = 1;

@Test
public void testTripProvidedValues() {
Expand All @@ -28,25 +25,12 @@ public void testTripProvidedValues() {
assertEquals(BikeAccess.NOT_ALLOWED, BikeAccessMapper.mapForTrip(trip));
}

@Test
public void testLegacyTripProvidedValues() {
Trip trip = new Trip();
assertEquals(BikeAccess.UNKNOWN, BikeAccessMapper.mapForTrip(trip));

trip.setTripBikesAllowed(TRIP_BIKES_ALLOWED);
assertEquals(BikeAccess.ALLOWED, BikeAccessMapper.mapForTrip(trip));

trip.setTripBikesAllowed(TRIP_BIKES_NOT_ALLOWED);
assertEquals(BikeAccess.NOT_ALLOWED, BikeAccessMapper.mapForTrip(trip));
}

@Test
public void testTripProvidedValuesPrecedence() {
Trip trip = new Trip();
assertEquals(BikeAccess.UNKNOWN, BikeAccessMapper.mapForTrip(trip));

trip.setBikesAllowed(BIKES_ALLOWED);
trip.setTripBikesAllowed(TRIP_BIKES_NOT_ALLOWED);
assertEquals(BikeAccess.ALLOWED, BikeAccessMapper.mapForTrip(trip));
}

Expand All @@ -61,26 +45,4 @@ public void testRouteProvidedValues() {
route.setBikesAllowed(BIKES_NOT_ALLOWED);
assertEquals(BikeAccess.NOT_ALLOWED, BikeAccessMapper.mapForRoute(route));
}

@Test
public void testLegacyRouteProvidedValues() {
Route route = new Route();
assertEquals(BikeAccess.UNKNOWN, BikeAccessMapper.mapForRoute(route));

route.setRouteBikesAllowed(ROUTE_BIKES_ALLOWED);
assertEquals(BikeAccess.ALLOWED, BikeAccessMapper.mapForRoute(route));

route.setRouteBikesAllowed(ROUTE_BIKES_NOT_ALLOWED);
assertEquals(BikeAccess.NOT_ALLOWED, BikeAccessMapper.mapForRoute(route));
}

@Test
public void testRouteProvidedValuesPrecedence() {
Route route = new Route();
assertEquals(BikeAccess.UNKNOWN, BikeAccessMapper.mapForRoute(route));

route.setBikesAllowed(BIKES_ALLOWED);
route.setRouteBikesAllowed(ROUTE_BIKES_NOT_ALLOWED);
assertEquals(BikeAccess.ALLOWED, BikeAccessMapper.mapForRoute(route));
}
}

0 comments on commit 2f0ccd8

Please sign in to comment.