diff --git a/src/main/java/ch/naviqore/gtfs/schedule/GtfsScheduleParser.java b/src/main/java/ch/naviqore/gtfs/schedule/GtfsScheduleParser.java index cf43e8f4..9f469c7c 100644 --- a/src/main/java/ch/naviqore/gtfs/schedule/GtfsScheduleParser.java +++ b/src/main/java/ch/naviqore/gtfs/schedule/GtfsScheduleParser.java @@ -4,6 +4,9 @@ import ch.naviqore.gtfs.schedule.type.ExceptionType; import ch.naviqore.gtfs.schedule.type.RouteType; import ch.naviqore.gtfs.schedule.type.ServiceDayTime; +import lombok.extern.log4j.Log4j2; +import org.apache.commons.csv.CSVRecord; + import java.time.DayOfWeek; import java.time.LocalDate; import java.time.format.DateTimeFormatter; @@ -12,8 +15,6 @@ import java.util.Map; import java.util.Set; import java.util.function.Consumer; -import lombok.extern.log4j.Log4j2; -import org.apache.commons.csv.CSVRecord; /** * GTFS CSV records parser @@ -39,13 +40,12 @@ public GtfsScheduleParser(GtfsScheduleBuilder builder) { public void parse(CSVRecord record, GtfsScheduleFile fileType) { Set warnings = EnumSet.noneOf(GtfsScheduleFile.class); parsers.getOrDefault(fileType, r -> { - if (!warnings.contains(fileType)) { - log.warn("Unsupported GTFS file type for parsing: {}", fileType); - } else { - warnings.add(fileType); - } - }) - .accept(record); + if (!warnings.contains(fileType)) { + log.warn("Unsupported GTFS file type for parsing: {}", fileType); + } else { + warnings.add(fileType); + } + }).accept(record); } private void initializeParsers() { diff --git a/src/main/java/ch/naviqore/gtfs/schedule/GtfsScheduleReader.java b/src/main/java/ch/naviqore/gtfs/schedule/GtfsScheduleReader.java index e5d7dd13..696ce9d7 100644 --- a/src/main/java/ch/naviqore/gtfs/schedule/GtfsScheduleReader.java +++ b/src/main/java/ch/naviqore/gtfs/schedule/GtfsScheduleReader.java @@ -56,10 +56,11 @@ private static void readFromZip(File zipFile, GtfsScheduleParser parser) throws ZipEntry entry = zf.getEntry(fileType.getFileName()); if (entry != null) { log.info("Reading GTFS file from ZIP: {}", entry.getName()); - try (InputStreamReader reader = new InputStreamReader( - BOMInputStream.builder().setInputStream(zf.getInputStream(entry)) - .setByteOrderMarks(ByteOrderMark.UTF_8).setInclude(false).get(), - StandardCharsets.UTF_8)) { + try (InputStreamReader reader = new InputStreamReader(BOMInputStream.builder() + .setInputStream(zf.getInputStream(entry)) + .setByteOrderMarks(ByteOrderMark.UTF_8) + .setInclude(false) + .get(), StandardCharsets.UTF_8)) { readCsvRecords(reader, parser, fileType); } } else { @@ -69,16 +70,19 @@ private static void readFromZip(File zipFile, GtfsScheduleParser parser) throws } } - private static void readCsvFile(File file, GtfsScheduleParser parser, GtfsScheduleFile fileType) throws IOException { - try (FileInputStream fileInputStream = new FileInputStream( - file); BOMInputStream bomInputStream = BOMInputStream.builder().setInputStream(fileInputStream) - .setByteOrderMarks(ByteOrderMark.UTF_8).get(); InputStreamReader reader = new InputStreamReader( - bomInputStream, StandardCharsets.UTF_8)) { + private static void readCsvFile(File file, GtfsScheduleParser parser, + GtfsScheduleFile fileType) throws IOException { + try (FileInputStream fileInputStream = new FileInputStream(file); + BOMInputStream bomInputStream = BOMInputStream.builder() + .setInputStream(fileInputStream) + .setByteOrderMarks(ByteOrderMark.UTF_8) + .get(); InputStreamReader reader = new InputStreamReader(bomInputStream, StandardCharsets.UTF_8)) { readCsvRecords(reader, parser, fileType); } } - private static void readCsvRecords(InputStreamReader reader, GtfsScheduleParser recordParser, GtfsScheduleFile fileType) throws IOException { + private static void readCsvRecords(InputStreamReader reader, GtfsScheduleParser recordParser, + GtfsScheduleFile fileType) throws IOException { CSVFormat format = CSVFormat.DEFAULT.builder().setHeader().setIgnoreHeaderCase(true).setTrim(true).build(); try (CSVParser csvParser = new CSVParser(reader, format)) { log.debug("CSV Headers: {}", csvParser.getHeaderMap().keySet()); diff --git a/src/main/java/ch/naviqore/gtfs/schedule/model/Calendar.java b/src/main/java/ch/naviqore/gtfs/schedule/model/Calendar.java index 52e7940a..696e2902 100644 --- a/src/main/java/ch/naviqore/gtfs/schedule/model/Calendar.java +++ b/src/main/java/ch/naviqore/gtfs/schedule/model/Calendar.java @@ -1,18 +1,14 @@ package ch.naviqore.gtfs.schedule.model; import ch.naviqore.gtfs.schedule.type.ExceptionType; -import java.time.DayOfWeek; -import java.time.LocalDate; -import java.util.ArrayList; -import java.util.EnumSet; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; import lombok.AccessLevel; import lombok.Getter; import lombok.RequiredArgsConstructor; +import java.time.DayOfWeek; +import java.time.LocalDate; +import java.util.*; + @RequiredArgsConstructor(access = AccessLevel.PACKAGE) @Getter public final class Calendar { @@ -25,7 +21,8 @@ public final class Calendar { private final List trips = new ArrayList<>(); /** - * Determines if the service is operational on a specific day, considering both regular service days and exceptions. + * Determines if the service is operational on a specific day, considering both regular service days and + * exceptions. * * @param date the date to check for service availability * @return true if the service is operational on the given date, false otherwise diff --git a/src/main/java/ch/naviqore/gtfs/schedule/model/GtfsSchedule.java b/src/main/java/ch/naviqore/gtfs/schedule/model/GtfsSchedule.java index 04db8fb1..7706ca7a 100644 --- a/src/main/java/ch/naviqore/gtfs/schedule/model/GtfsSchedule.java +++ b/src/main/java/ch/naviqore/gtfs/schedule/model/GtfsSchedule.java @@ -24,7 +24,8 @@ public class GtfsSchedule { * @return GtfsScheduleDay containing only the active routes, stops, and trips for the specified date. */ public GtfsScheduleDay getScheduleForDay(LocalDate date) { - Map activeTrips = trips.entrySet().stream() + Map activeTrips = trips.entrySet() + .stream() .filter(entry -> entry.getValue().getCalendar().isServiceAvailable(date)) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); diff --git a/src/main/java/ch/naviqore/gtfs/schedule/model/StopTime.java b/src/main/java/ch/naviqore/gtfs/schedule/model/StopTime.java index 85b320b0..48712f74 100644 --- a/src/main/java/ch/naviqore/gtfs/schedule/model/StopTime.java +++ b/src/main/java/ch/naviqore/gtfs/schedule/model/StopTime.java @@ -19,4 +19,3 @@ public int compareTo(StopTime o) { return this.departure.compareTo(o.departure); } } - diff --git a/src/main/java/ch/naviqore/gtfs/schedule/type/RouteType.java b/src/main/java/ch/naviqore/gtfs/schedule/type/RouteType.java index 9c17d404..35432d82 100644 --- a/src/main/java/ch/naviqore/gtfs/schedule/type/RouteType.java +++ b/src/main/java/ch/naviqore/gtfs/schedule/type/RouteType.java @@ -12,8 +12,10 @@ public enum RouteType { RAIL(2, "Rail. Used for intercity or long-distance travel."), BUS(3, "Bus. Used for short- and long-distance bus routes."), FERRY(4, "Ferry. Used for short- and long-distance boat service."), - CABLE_TRAM(5, "Cable tram. Used for street-level rail cars where the cable runs beneath the vehicle (e.g., cable car in San Francisco)."), - AERIAL_LIFT(6, "Aerial lift, suspended cable car (e.g., gondola lift, aerial tramway). Cable transport where cabins, cars, gondolas or open chairs are suspended by means of one or more cables."), + CABLE_TRAM(5, + "Cable tram. Used for street-level rail cars where the cable runs beneath the vehicle (e.g., cable car in San Francisco)."), + AERIAL_LIFT(6, + "Aerial lift, suspended cable car (e.g., gondola lift, aerial tramway). Cable transport where cabins, cars, gondolas or open chairs are suspended by means of one or more cables."), FUNICULAR(7, "Funicular. Any rail system designed for steep inclines."), TROLLEYBUS(11, "Trolleybus. Electric buses that draw power from overhead wires using poles."), MONORAIL(12, "Monorail. Railway in which the track consists of a single rail or a beam."); diff --git a/src/main/java/ch/naviqore/raptor/model/RouteTraversalBuilder.java b/src/main/java/ch/naviqore/raptor/model/RouteTraversalBuilder.java index fa98267c..a9442964 100644 --- a/src/main/java/ch/naviqore/raptor/model/RouteTraversalBuilder.java +++ b/src/main/java/ch/naviqore/raptor/model/RouteTraversalBuilder.java @@ -1,12 +1,11 @@ package ch.naviqore.raptor.model; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; import lombok.AccessLevel; import lombok.NoArgsConstructor; +import java.util.HashMap; +import java.util.Map; + @NoArgsConstructor(access = AccessLevel.PACKAGE) public class RouteTraversalBuilder { @@ -29,7 +28,7 @@ public RouteTraversalBuilder addStopTime() { return this; } - public RouteTraversalBuilder addRouteStop(String id, String routeid) { + public RouteTraversalBuilder addRouteStop(String id, String routeId) { if (routes.containsKey(id)) { throw new IllegalArgumentException("Route " + id + " already exists"); } diff --git a/src/test/java/ch/naviqore/gtfs/schedule/GtfsScheduleBenchmark.java b/src/test/java/ch/naviqore/gtfs/schedule/GtfsScheduleBenchmark.java index 1349993a..3ea9957b 100644 --- a/src/test/java/ch/naviqore/gtfs/schedule/GtfsScheduleBenchmark.java +++ b/src/test/java/ch/naviqore/gtfs/schedule/GtfsScheduleBenchmark.java @@ -3,11 +3,12 @@ import ch.naviqore.gtfs.schedule.GtfsScheduleBenchmarkData.Dataset; import ch.naviqore.gtfs.schedule.model.GtfsSchedule; import ch.naviqore.gtfs.schedule.model.GtfsScheduleDay; -import java.io.IOException; -import java.time.LocalDate; import lombok.AccessLevel; import lombok.NoArgsConstructor; +import java.io.IOException; +import java.time.LocalDate; + @NoArgsConstructor(access = AccessLevel.PRIVATE) public final class GtfsScheduleBenchmark { diff --git a/src/test/java/ch/naviqore/gtfs/schedule/GtfsScheduleBenchmarkData.java b/src/test/java/ch/naviqore/gtfs/schedule/GtfsScheduleBenchmarkData.java index c2c31a31..c072e03a 100644 --- a/src/test/java/ch/naviqore/gtfs/schedule/GtfsScheduleBenchmarkData.java +++ b/src/test/java/ch/naviqore/gtfs/schedule/GtfsScheduleBenchmarkData.java @@ -23,10 +23,12 @@ @Log4j2 public final class GtfsScheduleBenchmarkData { private static final Path DATA_DIRECTORY = Path.of("benchmark/input"); - private static final HttpClient httpClient = HttpClient.newBuilder().followRedirects(HttpClient.Redirect.ALWAYS) + private static final HttpClient httpClient = HttpClient.newBuilder() + .followRedirects(HttpClient.Redirect.ALWAYS) .build(); - public static void downloadFile(String fileURL, Path directory, String fileName) throws IOException, InterruptedException { + public static void downloadFile(String fileURL, Path directory, + String fileName) throws IOException, InterruptedException { Path filePath = directory.resolve(fileName); if (Files.notExists(filePath)) { log.info("Downloading file: {}", fileURL); @@ -69,8 +71,8 @@ public static String get(Dataset dataset) throws IOException, InterruptedExcepti @RequiredArgsConstructor(access = AccessLevel.PRIVATE) @Getter public enum Dataset { - SWITZERLAND("https://opentransportdata.swiss/en/dataset/timetable-2024-gtfs2020/permalink"), GERMANY( - "https://download.gtfs.de/germany/free/latest.zip"); + SWITZERLAND("https://opentransportdata.swiss/en/dataset/timetable-2024-gtfs2020/permalink"), + GERMANY("https://download.gtfs.de/germany/free/latest.zip"); private final String url; diff --git a/src/test/java/ch/naviqore/gtfs/schedule/GtfsScheduleTestData.java b/src/test/java/ch/naviqore/gtfs/schedule/GtfsScheduleTestData.java index 768e71de..5d26b32c 100644 --- a/src/test/java/ch/naviqore/gtfs/schedule/GtfsScheduleTestData.java +++ b/src/test/java/ch/naviqore/gtfs/schedule/GtfsScheduleTestData.java @@ -2,11 +2,7 @@ import org.junit.jupiter.api.io.TempDir; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; +import java.io.*; import java.nio.file.Path; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream;