-
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.
- Extract a service day from the schedule. - Introduce Initializable interface to mark objects that need construction.
- Loading branch information
Showing
10 changed files
with
218 additions
and
12 deletions.
There are no files selected for viewing
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
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
36 changes: 36 additions & 0 deletions
36
src/main/java/ch/naviqore/gtfs/schedule/model/GtfsScheduleDay.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,36 @@ | ||
package ch.naviqore.gtfs.schedule.model; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.time.LocalDate; | ||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
/** | ||
* GTFS Schedule Service Day | ||
* <p> | ||
* Represents a daily snapshot of the GTFS schedule, containing only the active services on a specific date. | ||
*/ | ||
@RequiredArgsConstructor(access = AccessLevel.PACKAGE) | ||
public class GtfsScheduleDay { | ||
|
||
@Getter | ||
private final LocalDate date; | ||
private final Map<String, Stop> stops; | ||
private final Map<String, Route> routes; | ||
private final Map<String, Trip> trips; | ||
|
||
public Map<String, Stop> getStops() { | ||
return Collections.unmodifiableMap(stops); | ||
} | ||
|
||
public Map<String, Route> getRoutes() { | ||
return Collections.unmodifiableMap(routes); | ||
} | ||
|
||
public Map<String, Trip> getTrips() { | ||
return Collections.unmodifiableMap(trips); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/ch/naviqore/gtfs/schedule/model/Initializable.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,19 @@ | ||
package ch.naviqore.gtfs.schedule.model; | ||
|
||
/** | ||
* Initializable class | ||
* <p> | ||
* This internal interface should be implemented by classes that require initialization steps to be executed before they | ||
* are considered fully ready and operational. This interface is designed to enforce a consistent initialization pattern | ||
* across different components of the GTFS (General Transit Feed Specification) schedule model. | ||
* | ||
* @author munterfi | ||
*/ | ||
interface Initializable { | ||
|
||
/** | ||
* Initializes the implementing object. | ||
*/ | ||
void initialize(); | ||
|
||
} |
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 |
---|---|---|
@@ -1,4 +1,47 @@ | ||
package ch.naviqore.gtfs.schedule.model; | ||
|
||
public record Stop(String id, String name, double lat, double lon) { | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
@RequiredArgsConstructor(access = AccessLevel.PACKAGE) | ||
@Getter | ||
public final class Stop implements Initializable { | ||
private final String id; | ||
private final String name; | ||
private final double lat; | ||
private final double lon; | ||
private final List<StopTime> stopTimes = new ArrayList<>(); | ||
|
||
void addStopTime(StopTime stopTime) { | ||
stopTimes.add(stopTime); | ||
} | ||
|
||
@Override | ||
public void initialize() { | ||
Collections.sort(stopTimes); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj == this) return true; | ||
if (obj == null || obj.getClass() != this.getClass()) return false; | ||
var that = (Stop) obj; | ||
return Objects.equals(this.id, that.id); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(id); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Stop[" + "id=" + id + ", " + "name=" + name + ", " + "lat=" + lat + ", " + "lon=" + 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
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