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
40 changes: 34 additions & 6 deletions src/main/java/org/mtransit/parser/DefaultAgencyTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -811,18 +811,33 @@ public boolean removeRouteLongNameFromDirectionHeadsign() {
return Configs.getRouteConfig().getDirectionHeadsignRemoveRouteLongName();
}

@Override
public boolean removeRouteShortNameFromDirectionHeadsign() {
return Configs.getRouteConfig().getDirectionHeadsignRemoveRouteShortName();
}

@Override
public boolean removeRouteDescFromDirectionHeadsign() {
return Configs.getRouteConfig().getDirectionHeadsignRemoveRouteDesc();
}

/**
* @param directionId {@link org.mtransit.parser.gtfs.data.GDirectionId} (0 or 1 or missing/generated)
*/
@Override
public @NotNull String cleanDirectionHeadsign(@Nullable GRoute gRoute, int directionId, boolean fromStopName, @NotNull String directionHeadSign) {
if (gRoute != null && removeRouteLongNameFromDirectionHeadsign()
&& directionHeadSign.equals(gRoute.getRouteLongNameOrDefault())) {
//noinspection deprecation
return cleanDirectionHeadsign(directionId, fromStopName, "");
if (gRoute != null) {
if (removeRouteLongNameFromDirectionHeadsign() && directionHeadSign.equals(gRoute.getRouteLongNameOrDefault())) {
directionHeadSign = "";
} else if (removeRouteShortNameFromDirectionHeadsign() && directionHeadSign.equals(gRoute.getRouteShortName())) {
directionHeadSign = "";
} else if (removeRouteDescFromDirectionHeadsign() && directionHeadSign.equals(gRoute.getRouteDescOrDefault())) {
directionHeadSign = "";
}
}
//noinspection deprecation
return cleanDirectionHeadsign(directionId, fromStopName, directionHeadSign);
directionHeadSign = cleanDirectionHeadsign(directionId, fromStopName, directionHeadSign);
return directionHeadSign;
}

@SuppressWarnings("DeprecatedIsStillUsed")
Expand All @@ -840,7 +855,8 @@ public String cleanDirectionHeadsign(int directionId, boolean fromStopName, @Not
@NotNull
@Override
public String cleanDirectionHeadsign(boolean fromStopName, @NotNull String directionHeadSign) {
return cleanTripHeadsign(directionHeadSign);
directionHeadSign = cleanTripHeadsign(directionHeadSign);
return directionHeadSign;
}

@Override
Expand Down Expand Up @@ -914,6 +930,9 @@ public int getDirectionType() {
@NotNull
@Override
public List<Integer> getDirectionTypes() {
if (!Configs.getRouteConfig().getDirectionTypes().isEmpty()) {
return Configs.getRouteConfig().getDirectionTypes();
}
//noinspection deprecation
final int deprecatedDirectionType = getDirectionType();
if (deprecatedDirectionType != -1
Expand Down Expand Up @@ -1164,9 +1183,18 @@ public String cleanStopHeadSign(@NotNull String stopHeadsign) {
return cleanTripHeadsign(cleanStopHeadsign);
}

@Override
public @Nullable String getStopCodePrependIfMissing() {
return Configs.getRouteConfig().getStopCodePrependIfMissing();
}

@NotNull
@Override
public String getStopCode(@NotNull GStop gStop) {
final String prepend = getStopCodePrependIfMissing();
if (prepend != null && !gStop.getStopCode().startsWith(prepend)) {
return prepend + gStop.getStopCode();
}
return gStop.getStopCode();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,16 @@ data class RouteConfig(
@SerialName("trip_id_clean_merged")
val tripIdCleanMerged: Boolean = false, // OPT-IN feature
// DIRECTION
@SerialName("direction_types")
val directionTypes: List<Int> = emptyList(),
@SerialName("direction_headsign_cleaners")
val directionHeadsignCleaners: List<Cleaner> = emptyList(),
@SerialName("direction_headsign_remove_route_long_name")
val directionHeadsignRemoveRouteLongName: Boolean = false, // OPT-IN feature
@SerialName("direction_headsign_remove_route_short_name")
val directionHeadsignRemoveRouteShortName: Boolean = false, // OPT-IN feature
@SerialName("direction_headsign_remove_route_desc")
val directionHeadsignRemoveRouteDesc: Boolean = false, // OPT-IN feature
@SerialName("direction_splitter_enabled")
val directionSplitterEnabled: Boolean = false, // OPT-IN feature
@SerialName("direction_finder_enabled")
Expand All @@ -73,6 +79,8 @@ data class RouteConfig(
val useStopCodeForStopId: Boolean = false, // OPT-IN feature
@SerialName("stop_code_to_stop_id_configs")
val stopCodeToStopIdConfigs: List<StopCodeToStopIdConfig> = emptyList(),
@SerialName("stop_code_prepend_if_missing")
val stopCodePrependIfMissing: String? = null, // optional
@SerialName("stop_headsign_remove_trip_headsign")
val stopHeadsignRemoveTripHeadsign: Boolean = false, // OPT-IN feature
@SerialName("stop_headsign_remove_route_long_name")
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/mtransit/parser/gtfs/GAgencyTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ public interface GAgencyTools {

boolean removeRouteLongNameFromDirectionHeadsign();

boolean removeRouteShortNameFromDirectionHeadsign();

boolean removeRouteDescFromDirectionHeadsign();

@NotNull
String cleanDirectionHeadsign(@Nullable GRoute gRoute, int directionId, boolean fromStopName, @NotNull String directionHeadSign);

Expand Down Expand Up @@ -301,6 +305,8 @@ public interface GAgencyTools {
@NotNull
String cleanStopHeadSign(@NotNull String stopHeadsign);

@Nullable String getStopCodePrependIfMissing();

@NotNull
String getStopCode(@NotNull GStop gStop);

Expand Down