Skip to content

Commit

Permalink
Merge pull request opentripplanner#6249 from leonardehrenfried/naming…
Browse files Browse the repository at this point in the history
…-conventions

Rename all methods in TransitService according to naming conventions
  • Loading branch information
leonardehrenfried authored Nov 28, 2024
2 parents 669d71f + aacd1d7 commit 996fa3f
Show file tree
Hide file tree
Showing 79 changed files with 389 additions and 424 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ static void setup() {
.build();

@Override
public List<TransitMode> getModesOfStopLocation(StopLocation stop) {
public List<TransitMode> findTransitModes(StopLocation stop) {
if (stop.getVehicleType() != null) {
return List.of(stop.getVehicleType());
} else {
Expand All @@ -144,15 +144,15 @@ public List<TransitMode> getModesOfStopLocation(StopLocation stop) {
}

@Override
public Agency getAgencyForId(FeedScopedId id) {
public Agency getAgency(FeedScopedId id) {
if (id.equals(BVG.getId())) {
return BVG;
}
return null;
}

@Override
public Set<Route> getRoutesForStop(StopLocation stop) {
public Set<Route> findRoutes(StopLocation stop) {
return Set.of(TimetableRepositoryForTest.route("route1").withAgency(BVG).build());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public TestTransitService(TimetableRepository timetableRepository) {
}

@Override
public Set<Route> getRoutesForStop(StopLocation stop) {
public Set<Route> findRoutes(StopLocation stop) {
return Set.of(
TimetableRepositoryForTest.route("1").withMode(TransitMode.RAIL).withGtfsType(100).build()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public TransitStopVertex getStopVertexForStopId(FeedScopedId stopId) {

@Override
public Collection<PathTransfer> getTransfersFromStop(StopLocation stop) {
return transitService.getTransfersByStop(stop);
return transitService.findPathTransfers(stop);
}

@Override
Expand All @@ -207,7 +207,7 @@ public Collection<PathTransfer> getTransfersToStop(StopLocation stop) {

@Override
public boolean isDateActive(FlexServiceDate date, FlexTrip<?, ?> trip) {
int serviceCode = transitService.getServiceCodeForId(trip.getTrip().getServiceId());
int serviceCode = transitService.getServiceCode(trip.getTrip().getServiceId());
return date.isTripServiceRunning(serviceCode);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ private static Optional<LuceneStopCluster> map(List<StopLocation> stopLocations)
}

private List<Agency> agenciesForStopLocation(StopLocation stop) {
return transitService.getRoutesForStop(stop).stream().map(Route::getAgency).distinct().toList();
return transitService.findRoutes(stop).stream().map(Route::getAgency).distinct().toList();
}

private List<Agency> agenciesForStopLocationsGroup(StopLocationsGroup group) {
Expand All @@ -190,7 +190,7 @@ StopCluster.Location toLocation(FeedScopedId id) {
var loc = transitService.getStopLocation(id);
if (loc != null) {
var feedPublisher = toFeedPublisher(transitService.getFeedInfo(id.getFeedId()));
var modes = transitService.getModesOfStopLocation(loc).stream().map(Enum::name).toList();
var modes = transitService.findTransitModes(loc).stream().map(Enum::name).toList();
var agencies = agenciesForStopLocation(loc)
.stream()
.map(StopClusterMapper::toAgency)
Expand All @@ -209,7 +209,7 @@ StopCluster.Location toLocation(FeedScopedId id) {
var group = transitService.getStopLocationsGroup(id);
var feedPublisher = toFeedPublisher(transitService.getFeedInfo(id.getFeedId()));
var modes = transitService
.getModesOfStopLocationsGroup(group)
.findTransitModes(group)
.stream()
.map(Enum::name)
.toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public static GraphStats build(OtpServerRequestContext context) {
new StreetStats(edgeTypes, vertexTypes),
new TransitStats(
stopCounts,
transitService.getAllTrips().size(),
transitService.getAllTripPatterns().size(),
transitService.getAllRoutes().size(),
transitService.listTrips().size(),
transitService.listTripPatterns().size(),
transitService.listRoutes().size(),
constrainedTransferCounts
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ private TxPoint pointInfo(TransferPoint p, boolean boarding) {
if (p instanceof TripTransferPoint tp) {
var trip = tp.getTrip();
var route = trip.getRoute();
var ptn = transitService.getPatternForTrip(trip);
var ptn = transitService.findPattern(trip);
r.operator = getName(trip.getOperator());
r.type = "Trip";
r.entityId = trip.getId().getId();
Expand All @@ -162,7 +162,7 @@ private TxPoint pointInfo(TransferPoint p, boolean boarding) {
addLocation(r, ptn, stop, trip, boarding);
} else if (p instanceof RouteStopTransferPoint rp) {
var route = rp.getRoute();
var ptn = transitService.getPatternsForRoute(route).stream().findFirst().orElse(null);
var ptn = transitService.findPatterns(route).stream().findFirst().orElse(null);
r.operator = getName(route.getOperator());
r.type = "Route";
r.entityId = route.getId().getId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public String getTransfersAsCsv() {
@Produces(MediaType.TEXT_PLAIN)
public String getTransitGroupPriorities() {
return TransitGroupPriorityReport.build(
transitService.getAllTripPatterns(),
transitService.listTripPatterns(),
defaultRequest.journey().transit()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public ApiRouterInfo(
this.buildTime = Date.from(graph.buildTime);
this.transitServiceStarts = transitService.getTransitServiceStarts().toEpochSecond();
this.transitServiceEnds = transitService.getTransitServiceEnds().toEpochSecond();
this.transitModes = ModeMapper.mapToApi(transitService.getTransitModes());
this.transitModes = ModeMapper.mapToApi(transitService.listTransitModes());
this.envelope = envelope;
this.hasBikeSharing = mapHasBikeSharing(vehicleRentalService);
this.hasBikePark = mapHasBikePark(vehicleParkingService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static List<ApiTravelOption> makeOptions(
TransitService transitService
) {
return makeOptions(
transitService.getTransitModes(),
transitService.listTransitModes(),
vehicleRentalService.hasRentalBikes(),
vehicleParkingService.hasBikeParking(),
vehicleParkingService.hasCarParking()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public IndexAPI(
@GET
@Path("/feeds")
public Collection<String> getFeeds() {
return transitService().getFeedIds();
return transitService().listFeedIds();
}

@GET
Expand All @@ -108,7 +108,7 @@ public ApiFeedInfo getFeedInfo(@PathParam("feedId") String feedId) {
@Path("/agencies/{feedId}")
public Collection<ApiAgency> getAgencies(@PathParam("feedId") String feedId) {
Collection<Agency> agencies = transitService()
.getAgencies()
.listAgencies()
.stream()
.filter(agency -> agency.getId().getFeedId().equals(feedId))
.collect(Collectors.toList());
Expand Down Expand Up @@ -138,7 +138,7 @@ public Response getAgencyRoutes(
var agency = agency(feedId, agencyId);

Collection<Route> routes = transitService()
.getAllRoutes()
.listRoutes()
.stream()
.filter(r -> r.getAgency() == agency)
.collect(Collectors.toList());
Expand Down Expand Up @@ -235,7 +235,7 @@ public List<ApiStopShort> getStopsInRadius(
public List<ApiRouteShort> getRoutesForStop(@PathParam("stopId") String stopId) {
var stop = stop(stopId);
return transitService()
.getPatternsForStop(stop)
.findPatterns(stop)
.stream()
.map(TripPattern::getRoute)
.map(RouteMapper::mapToApiShort)
Expand All @@ -247,7 +247,7 @@ public List<ApiRouteShort> getRoutesForStop(@PathParam("stopId") String stopId)
public List<ApiPatternShort> getPatternsForStop(@PathParam("stopId") String stopId) {
var stop = stop(stopId);
return transitService()
.getPatternsForStop(stop)
.findPatterns(stop)
.stream()
.map(TripPatternMapper::mapToApiShort)
.collect(Collectors.toList());
Expand Down Expand Up @@ -275,7 +275,7 @@ public Collection<ApiStopTimesInPattern> getStopTimesForStop(
: Instant.ofEpochSecond(startTimeSeconds);

return transitService()
.stopTimesForStop(
.findStopTimesInPattern(
stop(stopIdString),
startTime,
Duration.ofSeconds(timeRange),
Expand Down Expand Up @@ -303,7 +303,7 @@ public List<ApiStopTimesInPattern> getStoptimesForStopAndDate(
var stop = stop(stopId);
var serviceDate = parseServiceDate("date", date);
List<StopTimesInPattern> stopTimes = transitService()
.getStopTimesForStop(
.findStopTimesInPattern(
stop,
serviceDate,
omitNonPickups ? ArrivalDeparture.DEPARTURES : ArrivalDeparture.BOTH,
Expand All @@ -322,7 +322,7 @@ public Collection<ApiTransfer> getTransfers(@PathParam("stopId") String stopId)

// get the transfers for the stop
return transitService()
.getTransfersByStop(stop)
.findPathTransfers(stop)
.stream()
.map(TransferMapper::mapToApi)
.collect(Collectors.toList());
Expand All @@ -344,15 +344,15 @@ public Collection<ApiAlert> getAlertsForStop(@PathParam("stopId") String stopId)
@GET
@Path("/routes")
public List<ApiRouteShort> getRoutes(@QueryParam("hasStop") List<String> stopIds) {
Collection<Route> routes = transitService().getAllRoutes();
Collection<Route> routes = transitService().listRoutes();
// Filter routes to include only those that pass through all given stops
if (stopIds != null) {
// Protective copy, we are going to calculate the intersection destructively
routes = new ArrayList<>(routes);
for (String stopId : stopIds) {
var stop = stop(stopId);
Set<Route> routesHere = new HashSet<>();
for (TripPattern pattern : transitService().getPatternsForStop(stop)) {
for (TripPattern pattern : transitService().findPatterns(stop)) {
routesHere.add(pattern.getRoute());
}
routes.retainAll(routesHere);
Expand All @@ -372,7 +372,7 @@ public ApiRoute getRoute(@PathParam("routeId") String routeId) {
@GET
@Path("/routes/{routeId}/patterns")
public List<ApiPatternShort> getPatternsForRoute(@PathParam("routeId") String routeId) {
Collection<TripPattern> patterns = transitService().getPatternsForRoute(route(routeId));
Collection<TripPattern> patterns = transitService().findPatterns(route(routeId));
return TripPatternMapper.mapToApiShort(patterns);
}

Expand All @@ -383,7 +383,7 @@ public List<ApiStopShort> getStopsForRoute(@PathParam("routeId") String routeId)
var route = route(routeId);

Set<StopLocation> stops = new HashSet<>();
Collection<TripPattern> patterns = transitService().getPatternsForRoute(route);
Collection<TripPattern> patterns = transitService().findPatterns(route);
for (TripPattern pattern : patterns) {
stops.addAll(pattern.getStops());
}
Expand All @@ -396,7 +396,7 @@ public List<ApiStopShort> getStopsForRoute(@PathParam("routeId") String routeId)
public List<ApiTripShort> getTripsForRoute(@PathParam("routeId") String routeId) {
var route = route(routeId);

var patterns = transitService().getPatternsForRoute(route);
var patterns = transitService().findPatterns(route);
return patterns
.stream()
.flatMap(TripPattern::scheduledTripsAsStream)
Expand Down Expand Up @@ -445,7 +445,7 @@ public List<ApiTripTimeShort> getStoptimesForTrip(@PathParam("tripId") String tr
var pattern = tripPattern(trip);
// Note, we need the updated timetable not the scheduled one (which contains no real-time updates).
var table = transitService()
.getTimetableForTripPattern(pattern, LocalDate.now(transitService().getTimeZone()));
.findTimetable(pattern, LocalDate.now(transitService().getTimeZone()));
var tripTimesOnDate = TripTimeOnDate.fromTripTimes(table, trip);
return TripTimeMapper.mapToApi(tripTimesOnDate);
}
Expand All @@ -472,7 +472,7 @@ public Collection<ApiAlert> getAlertsForTrip(@PathParam("tripId") String tripId)
@GET
@Path("/patterns")
public List<ApiPatternShort> getPatterns() {
Collection<TripPattern> patterns = transitService().getAllTripPatterns();
Collection<TripPattern> patterns = transitService().listTripPatterns();
return TripPatternMapper.mapToApiShort(patterns);
}

Expand Down Expand Up @@ -589,7 +589,7 @@ private static NotFoundException notFoundException(String entity, String details
}

private Agency agency(String feedId, String agencyId) {
var agency = transitService().getAgencyForId(new FeedScopedId(feedId, agencyId));
var agency = transitService().getAgency(new FeedScopedId(feedId, agencyId));
if (agency == null) {
throw notFoundException("Agency", "feedId: " + feedId + ", agencyId: " + agencyId);
}
Expand All @@ -602,18 +602,18 @@ private StopLocation stop(String stopId) {
}

private Route route(String routeId) {
var route = transitService().getRouteForId(createId("routeId", routeId));
var route = transitService().getRoute(createId("routeId", routeId));
return validateExist("Route", route, "routeId", routeId);
}

private Trip trip(String tripId) {
var trip = transitService().getTripForId(createId("tripId", tripId));
var trip = transitService().getTrip(createId("tripId", tripId));
return validateExist("Trip", trip, "tripId", tripId);
}

private TripPattern tripPattern(String tripPatternId) {
var id = createId("patternId", tripPatternId);
var pattern = transitService().getTripPatternForId(id);
var pattern = transitService().getTripPattern(id);
return validateExist("TripPattern", pattern, "patternId", tripPatternId);
}

Expand All @@ -622,7 +622,7 @@ private TripPattern tripPatternForTripId(String tripId) {
}

private TripPattern tripPattern(Trip trip) {
var pattern = transitService().getPatternForTrip(trip);
var pattern = transitService().findPattern(trip);
return validateExist("TripPattern", pattern, "trip", trip.getId());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public TileJson getTileJson(
private List<FeedInfo> getFeedInfos() {
return serverContext
.transitService()
.getFeedIds()
.listFeedIds()
.stream()
.map(serverContext.transitService()::getFeedInfo)
.filter(Predicate.not(Objects::isNull))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static Predicate<RegularStop> forType(FilterType type, TransitService tra
return switch (type) {
case NONE -> NO_FILTER;
case SUNDAY_TO_SUNDAY_SERVICE_WEEK -> buildCurrentServiceWeekPredicate(
transitService::getPatternsForStop,
transitService::findPatterns,
trip ->
transitService.getCalendarService().getServiceDatesForServiceId(trip.getServiceId()),
() -> LocalDate.now(transitService.getTimeZone())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected AreaStopPropertyMapper(
}

protected static AreaStopPropertyMapper create(TransitService transitService, Locale locale) {
return new AreaStopPropertyMapper(transitService::getRoutesForStop, locale);
return new AreaStopPropertyMapper(transitService::findRoutes, locale);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public Collection<KeyValue> map(Station station) {
"type",
childStops
.stream()
.flatMap(stop -> transitService.getPatternsForStop(stop).stream())
.flatMap(stop -> transitService.findPatterns(stop).stream())
.map(tripPattern -> tripPattern.getMode().name())
.distinct()
.collect(Collectors.joining(","))
Expand All @@ -60,7 +60,7 @@ public Collection<KeyValue> map(Station station) {
OBJECT_MAPPER.writeValueAsString(
childStops
.stream()
.flatMap(stop -> transitService.getRoutesForStop(stop).stream())
.flatMap(stop -> transitService.findRoutes(stop).stream())
.distinct()
.map(route -> {
var obj = OBJECT_MAPPER.createObjectNode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public StationsLayerBuilder(

protected List<Geometry> getGeometries(Envelope query) {
return transitService
.getStations()
.listStations()
.stream()
.map(station -> {
Coordinate coordinate = station.getCoordinate().asJtsCoordinate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected Collection<KeyValue> map(RegularStop stop) {

var serviceDate = LocalDate.now(transitService.getTimeZone());
boolean stopTimesExist = transitService
.getStopTimesForStop(stop, serviceDate, ArrivalDeparture.BOTH, true)
.findStopTimesInPattern(stop, serviceDate, ArrivalDeparture.BOTH, true)
.stream()
.anyMatch(stopTime -> stopTime.times.size() > 0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected static Collection<KeyValue> getBaseKeyValues(
protected static String getRoutes(TransitService transitService, RegularStop stop) {
try {
var objects = transitService
.getRoutesForStop(stop)
.findRoutes(stop)
.stream()
.map(route -> {
var routeObject = OBJECT_MAPPER.createObjectNode();
Expand All @@ -76,7 +76,7 @@ protected static String getRoutes(TransitService transitService, RegularStop sto
}

protected static String getType(TransitService transitService, RegularStop stop) {
Collection<TripPattern> patternsForStop = transitService.getPatternsForStop(stop);
Collection<TripPattern> patternsForStop = transitService.findPatterns(stop);

return patternsForStop
.stream()
Expand Down
Loading

0 comments on commit 996fa3f

Please sign in to comment.