Skip to content

Commit

Permalink
Truncate route desc (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
TsimurSh authored Oct 1, 2024
2 parents c345299 + 2e1639e commit 2c5346e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions core/src/main/java/org/transitclock/gtfs/model/GtfsRoute.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import javax.annotation.concurrent.Immutable;

import com.google.common.base.Strings;
import lombok.Getter;
import lombok.ToString;
import org.apache.commons.csv.CSVRecord;
Expand Down Expand Up @@ -88,9 +89,7 @@ public GtfsRoute(CSVRecord record, boolean supplementalFile, String fileName) {
agencyId = getOptionalValue(record, "agency_id");
routeShortName = getOptionalValue(record, "route_short_name");
routeLongName = getOptionalValue(record, "route_long_name");
routeDesc = getOptionalValue(record, "route_desc").length() < 1024
? getOptionalValue(record, "route_desc")
: truncateToLimitSize(getOptionalValue(record, "route_desc"), 1024);
routeDesc = truncateToLimitSize(getOptionalValue(record, "route_desc"), 1024);
routeType = getRequiredUnlessSupplementalValue(record, "route_type");
routeURL = getOptionalValue(record, "route_url");
routeColor = getOptionalValue(record, "route_color");
Expand Down Expand Up @@ -182,6 +181,10 @@ public boolean shouldCreateUnscheduledBlock() {
}

private String truncateToLimitSize(String toTruncate, int maxSize) {
return toTruncate.substring(0, maxSize);
if (Strings.isNullOrEmpty(toTruncate) || toTruncate.length() <= maxSize) {
return toTruncate;
} else {
return toTruncate.substring(0, maxSize);
}
}
}

0 comments on commit 2c5346e

Please sign in to comment.