-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parse all required fields and fields
- Refactor entities into model package. - Add stop times to trip and trips to routes.
- Loading branch information
Showing
17 changed files
with
233 additions
and
39 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...ava/ch/naviqore/gtfs/schedule/Agency.java → .../naviqore/gtfs/schedule/model/Agency.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package ch.naviqore.gtfs.schedule; | ||
package ch.naviqore.gtfs.schedule.model; | ||
|
||
public record Agency(String agency, String name, String url, String timezone) { | ||
} |
45 changes: 45 additions & 0 deletions
45
src/main/java/ch/naviqore/gtfs/schedule/model/Calendar.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package ch.naviqore.gtfs.schedule.model; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.time.DayOfWeek; | ||
import java.time.LocalDate; | ||
import java.util.EnumSet; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
@RequiredArgsConstructor(access = AccessLevel.PACKAGE) | ||
@Getter | ||
public final class Calendar { | ||
private final String id; | ||
private final EnumSet<DayOfWeek> serviceDays; | ||
private final LocalDate startDate; | ||
private final LocalDate endDate; | ||
private final Map<LocalDate, CalendarDate> calendarDates = new HashMap<>(); | ||
|
||
void addCalendarDate(CalendarDate calendarDate) { | ||
calendarDates.put(calendarDate.date(), calendarDate); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj == this) return true; | ||
if (obj == null || obj.getClass() != this.getClass()) return false; | ||
var that = (Calendar) obj; | ||
return Objects.equals(this.id, that.id); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(id); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Calendar[" + "id=" + id + ", " + "serviceDays=" + serviceDays + ", " + "startDate=" + startDate + ", " + "endDate=" + endDate + ']'; | ||
} | ||
|
||
} |
4 changes: 3 additions & 1 deletion
4
.../naviqore/gtfs/schedule/CalendarDate.java → ...ore/gtfs/schedule/model/CalendarDate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../naviqore/gtfs/schedule/GtfsSchedule.java → ...ore/gtfs/schedule/model/GtfsSchedule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package ch.naviqore.gtfs.schedule.model; | ||
|
||
import ch.naviqore.gtfs.schedule.type.RouteType; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
@RequiredArgsConstructor(access = AccessLevel.PACKAGE) | ||
@Getter | ||
public final class Route { | ||
private final String id; | ||
private final Agency agency; | ||
private final String shortName; | ||
private final String longName; | ||
private final RouteType type; | ||
private final List<Trip> trips = new ArrayList<>(); | ||
|
||
void addTrip(Trip trip) { | ||
trips.add(trip); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj == this) return true; | ||
if (obj == null || obj.getClass() != this.getClass()) return false; | ||
var that = (Route) obj; | ||
return Objects.equals(this.id, that.id); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(id); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Route[" + "id=" + id + ", " + "agency=" + agency + ", " + "shortName=" + shortName + ", " + "longName=" + longName + ", " + "type=" + type + ']'; | ||
} | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
.../java/ch/naviqore/gtfs/schedule/Stop.java → ...ch/naviqore/gtfs/schedule/model/Stop.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package ch.naviqore.gtfs.schedule; | ||
package ch.naviqore.gtfs.schedule.model; | ||
|
||
public record Stop(String id, String name, double lat, double lon) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package ch.naviqore.gtfs.schedule.model; | ||
|
||
import ch.naviqore.gtfs.schedule.type.ServiceDayTime; | ||
|
||
public record StopTime(Stop stop, Trip trip, ServiceDayTime arrival, ServiceDayTime departure) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package ch.naviqore.gtfs.schedule.model; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
@RequiredArgsConstructor | ||
@Getter | ||
public final class Trip implements Comparable<Trip> { | ||
private final String id; | ||
private final Route route; | ||
private final Calendar calendar; | ||
private final List<StopTime> stopTimes = new ArrayList<>(); | ||
|
||
void addStopTime(StopTime stopTime) { | ||
stopTimes.add(stopTime); | ||
} | ||
|
||
@Override | ||
public int compareTo(Trip o) { | ||
// TODO: Sort stopTimes, then return first stop. | ||
return 0; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj == this) return true; | ||
if (obj == null || obj.getClass() != this.getClass()) return false; | ||
var that = (Trip) obj; | ||
return Objects.equals(this.id, that.id); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(id); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Trip[" + "id=" + id + ", " + "route=" + route + ", " + "calendar=" + calendar + ']'; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...naviqore/gtfs/schedule/ExceptionType.java → ...ore/gtfs/schedule/type/ExceptionType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../ch/naviqore/gtfs/schedule/RouteType.java → ...aviqore/gtfs/schedule/type/RouteType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/java/ch/naviqore/gtfs/schedule/type/ServiceDayTime.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package ch.naviqore.gtfs.schedule.type; | ||
|
||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
|
||
|
||
/** | ||
* Service day time | ||
* <p> | ||
* A service day may end after 24:00:00 and times like 25:30:00 are possible values. java.time.LocalTime does not | ||
* support this. Therefore, this time class is used to be able to cover service days bigger than 24 hours. | ||
* | ||
* @author munterfi | ||
*/ | ||
@EqualsAndHashCode | ||
@Getter | ||
public class ServiceDayTime implements Comparable<ServiceDayTime> { | ||
private final int totalSeconds; | ||
|
||
public ServiceDayTime(int hours, int minutes, int seconds) { | ||
this.totalSeconds = seconds + 60 * minutes + 3600 * hours; | ||
} | ||
|
||
public static ServiceDayTime parse(String timeString) { | ||
String[] parts = timeString.split(":"); | ||
int hours = Integer.parseInt(parts[0]); | ||
int minutes = Integer.parseInt(parts[1]); | ||
int seconds = Integer.parseInt(parts[2]); | ||
return new ServiceDayTime(hours, minutes, seconds); | ||
} | ||
|
||
@Override | ||
public int compareTo(ServiceDayTime o) { | ||
return Integer.compare(totalSeconds, o.totalSeconds); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
int hours = totalSeconds / 3600; | ||
int minutes = (totalSeconds % 3600) / 60; | ||
int seconds = totalSeconds % 60; | ||
return String.format("%02d:%02d:%02d", hours, minutes, seconds); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
src/test/java/ch/naviqore/gtfs/schedule/GtfsScheduleReaderIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters