Skip to content

Commit

Permalink
Use stringUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
sharhio committed Dec 14, 2023
1 parent 0cba479 commit 09c386a
Showing 1 changed file with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import org.opentripplanner.framework.lang.Sandbox;
import org.opentripplanner.framework.lang.StringUtils;
import org.opentripplanner.graph_builder.issue.api.DataImportIssueStore;
import org.opentripplanner.transit.model.framework.FeedScopedId;
import org.slf4j.Logger;
Expand Down Expand Up @@ -92,33 +93,33 @@ private Map<FeedScopedId, Double> readEmissions(InputStream stream, String feedI
String avgCo2PerVehiclePerKmString = reader.get("avg_co2_per_vehicle_per_km");
String avgPassengerCountString = reader.get("avg_passenger_count");

if (!exists(routeId)) {
if (!StringUtils.hasValue(routeId)) {
issueStore.add(
"InvalidEmissionData",
"Value for routeId is missing in the emissions.txt for line: %s.",
reader.getRawRecord()
);
}
if (!exists(avgCo2PerVehiclePerKmString)) {}
if (!StringUtils.hasValue(avgCo2PerVehiclePerKmString)) {}
{
issueStore.add(
"InvalidEmissionData",
"Value for avg_co2_per_vehicle_per_km is missing in the emissions.txt for route %s",
routeId
);
}
if (!exists(avgPassengerCountString)) {
if (!StringUtils.hasValue(avgPassengerCountString)) {
issueStore.add(
"InvalidEmissionData",
"Value for avg_passenger_count is missing in the emissions.txt for route %s",
routeId
);
}
if (
exists(feedId) &&
exists(routeId) &&
exists(avgCo2PerVehiclePerKmString) &&
exists(avgPassengerCountString)
StringUtils.hasValue(feedId) &&
StringUtils.hasValue(routeId) &&
StringUtils.hasValue(avgCo2PerVehiclePerKmString) &&
StringUtils.hasValue(avgPassengerCountString)
) {
Double avgCo2PerVehiclePerMeter = Double.parseDouble(avgCo2PerVehiclePerKmString) / 1000;
Double avgPassengerCount = Double.parseDouble(reader.get("avg_passenger_count"));
Expand All @@ -135,10 +136,6 @@ private Map<FeedScopedId, Double> readEmissions(InputStream stream, String feedI
return emissionsData;
}

private boolean exists(String s) {
return !s.isBlank() && !s.isEmpty();
}

private String readFeedId(InputStream stream) {
try {
CsvReader reader = new CsvReader(stream, StandardCharsets.UTF_8);
Expand Down

0 comments on commit 09c386a

Please sign in to comment.