Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/main/java/org/mtransit/parser/DefaultAgencyTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ public String cleanRouteLongName(@NotNull String routeLongName) {
}
routeLongName = Configs.getRouteConfig().cleanRouteLongName(routeLongName);
if (defaultStringsCleanerEnabled()) {
return StringsCleaner.cleanRouteLongName(routeLongName, getSupportedLanguages(), lowerUCStrings(), lowerUCWords(), getIgnoreUCWords());
return StringsCleaner.cleanRouteLongName(routeLongName, getSupportedLanguages(), getAgencyRouteType(), lowerUCStrings(), lowerUCWords(), getIgnoreUCWords());
}
return org.mtransit.commons.CleanUtils.cleanLabel(getFirstLanguageNN(), routeLongName);
}
Expand Down Expand Up @@ -692,6 +692,12 @@ public boolean excludeRouteNullable(@Nullable GRoute gRoute) {

@Override
public boolean excludeRoute(@NotNull GRoute gRoute) {
if (Configs.getRouteConfig().keepRoutes(gRoute)) {
return KEEP;
}
if (Configs.getRouteConfig().excludeRoutes(gRoute)) {
return EXCLUDE;
}
//noinspection ConstantConditions
if (getOriginalAgencyRouteType() == null) {
throw new MTLog.Fatal("ERROR: unspecified agency route type '%s'!", getOriginalAgencyRouteType());
Expand Down Expand Up @@ -746,7 +752,7 @@ public void setDirectionHeadsign(@NotNull MRoute mRoute, @NotNull MDirection mDi
public String cleanTripHeadsign(@NotNull String tripHeadsign) {
tripHeadsign = Configs.getRouteConfig().cleanTripHeadsign(tripHeadsign);
if (defaultStringsCleanerEnabled()) {
return StringsCleaner.cleanTripHeadsign(tripHeadsign, getSupportedLanguages(), lowerUCStrings(), lowerUCWords(), getIgnoreUCWords(), Configs.getRouteConfig().getTripHeadsignRemoveVia());
return StringsCleaner.cleanTripHeadsign(tripHeadsign, getSupportedLanguages(), getAgencyRouteType(), lowerUCStrings(), lowerUCWords(), getIgnoreUCWords(), Configs.getRouteConfig().getTripHeadsignRemoveVia());
}
return tripHeadsign;
}
Expand Down Expand Up @@ -1142,8 +1148,9 @@ public boolean excludeCalendar(@NotNull GCalendar gCalendar) {
@NotNull
@Override
public String cleanStopName(@NotNull String gStopName) {
gStopName = Configs.getRouteConfig().cleanStopName(gStopName);
if (defaultStringsCleanerEnabled()) {
return StringsCleaner.cleanStopName(gStopName, getSupportedLanguages(), lowerUCStrings(), lowerUCWords(), getIgnoreUCWords());
return StringsCleaner.cleanStopName(gStopName, getSupportedLanguages(), getAgencyRouteType(), lowerUCStrings(), lowerUCWords(), getIgnoreUCWords());
}
return org.mtransit.commons.CleanUtils.cleanLabel(getFirstLanguageNN(), gStopName);
}
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/org/mtransit/parser/config/gtfs/data/RouteConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import org.mtransit.parser.gtfs.data.GTrip

@Serializable
data class RouteConfig(
@SerialName("keep_routes")
val keepRoutes: List<RouteDef> = emptyList(), // force additional routes to be included (different types...)
@SerialName("exclude_routes")
val excludeRoutes: List<RouteDef> = emptyList(), // force additional routes to be excluded
// ID
@SerialName("default_route_id_enabled")
val defaultRouteIdEnabled: Boolean = false, // OPT-IN feature
Expand Down Expand Up @@ -91,6 +95,8 @@ data class RouteConfig(
val stopCodePrependIfMissing: String? = null, // optional
@SerialName("use_stop_id_hash_code")
val useStopIdHashCode: Boolean = false, // OPT-IN feature
@SerialName("stop_name_cleaners")
val stopNameCleaners: List<Cleaner> = emptyList(),
@SerialName("stop_headsign_remove_trip_headsign")
val stopHeadsignRemoveTripHeadsign: Boolean = false, // OPT-IN feature
@SerialName("stop_headsign_remove_route_long_name")
Expand All @@ -104,6 +110,14 @@ data class RouteConfig(
val allowInvalidStopTimesUntil: String? = null, // OPT-IN feature
) {

@Serializable
data class RouteDef(
@SerialName("route_id")
val routeId: String? = null,
@SerialName("route_short_name")
val routeShortName: String? = null,
)

@Serializable
data class RouteShortNameToRouteIdConfig(
@SerialName("route_short_name")
Expand Down Expand Up @@ -168,6 +182,20 @@ data class RouteConfig(
val ignoreCase: Boolean = false,
)

fun keepRoutes(gRoute: GRoute) =
this.keepRoutes.any {
//noinspection DiscouragedApi
it.routeId != null && gRoute.routeId == it.routeId
|| it.routeShortName != null && gRoute.routeShortName == it.routeShortName
}

fun excludeRoutes(gRoute: GRoute) =
this.excludeRoutes.any {
//noinspection DiscouragedApi
it.routeId != null && gRoute.routeId == it.routeId
|| it.routeShortName != null && gRoute.routeShortName == it.routeShortName
}

fun convertRouteIdFromShortNameNotSupported(routeShortName: String) =
this.routeShortNameToRouteIdConfigs
.singleOrNull { it.routeShortName == routeShortName }?.routeId
Expand Down Expand Up @@ -209,6 +237,9 @@ data class RouteConfig(
fun cleanTripHeadsign(tripHeadsign: String) =
cleanString(tripHeadsign, this.tripHeadsignCleaners)

fun cleanStopName(stopName: String) =
cleanString(stopName, this.stopNameCleaners)

private val _tripExcludes: List<Regex> by lazy {
this.tripExcludes.mapNotNull {
if (it.tripHeadsignRegex.isNullOrEmpty()) return@mapNotNull null
Expand Down