-
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.
Merge pull request #19 from naviqore/feature/NAV-52-define-interfaces…
…-for-service
- Loading branch information
Showing
19 changed files
with
332 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package ch.naviqore.service; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* A connection in a public transit schedule, consisting of multiple public transit legs and walks. | ||
*/ | ||
public interface Connection { | ||
|
||
List<Leg> getLegs(); | ||
|
||
} |
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,38 @@ | ||
package ch.naviqore.service; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
/** | ||
* Represents a leg of a connection, including its order, distance, and duration. | ||
*/ | ||
public interface Leg { | ||
|
||
LegType getLegType(); | ||
|
||
Location getSourceLocation(); | ||
|
||
Location getTargetLocation(); | ||
|
||
LocalDateTime getArrivalTime(); | ||
|
||
LocalDateTime getDepartureTime(); | ||
|
||
int getDistance(); | ||
|
||
int getDuration(); | ||
|
||
/** | ||
* The target public transit stop, if walk starts at a stop. | ||
*/ | ||
@Nullable | ||
Stop getSourceStop(); | ||
|
||
/** | ||
* The target public transit stop, if walk ends at a stop. | ||
*/ | ||
@Nullable | ||
Stop getTargetStop(); | ||
|
||
} |
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.service; | ||
|
||
public enum LegType { | ||
PUBLIC_TRANSIT, | ||
WALK | ||
} |
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,9 @@ | ||
package ch.naviqore.service; | ||
|
||
public interface Location { | ||
|
||
double getLatitude(); | ||
|
||
double getLongitude(); | ||
|
||
} |
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.service; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
public interface PublicTransitLeg extends Leg { | ||
|
||
StopTime getArrival(); | ||
|
||
StopTime getDeparture(); | ||
|
||
@Override | ||
@NotNull | ||
Stop getSourceStop(); | ||
|
||
@Override | ||
@NotNull | ||
Stop getTargetStop(); | ||
|
||
} |
109 changes: 109 additions & 0 deletions
109
src/main/java/ch/naviqore/service/PublicTransitService.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,109 @@ | ||
package ch.naviqore.service; | ||
|
||
import ch.naviqore.service.config.ConnectionQueryConfig; | ||
import ch.naviqore.service.exception.RouteNotFoundException; | ||
import ch.naviqore.service.exception.StopNotFoundException; | ||
import ch.naviqore.service.exception.TripNotFoundException; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* Public transit service with methods to retrieve stops, trips, routes, and connections. | ||
*/ | ||
public interface PublicTransitService { | ||
|
||
/** | ||
* Searches for stops by name. | ||
* | ||
* @param like the search term to match against stop names | ||
* @param searchType the type of search to perform (STARTS_WITH, ENDS_WITH, CONTAINS, EXACT) | ||
* @return a list of stops matching the search criteria | ||
*/ | ||
List<Stop> getStops(String like, SearchType searchType); | ||
|
||
/** | ||
* Retrieves the nearest stop to a given location. | ||
* | ||
* @param location the location to search around | ||
* @return the nearest stop to the specified location, or null if no stop is found | ||
*/ | ||
@Nullable | ||
Stop getNearestStop(Location location); | ||
|
||
/** | ||
* Retrieves the nearest stops to a given location within a specified radius. | ||
* | ||
* @param location the location to search around | ||
* @param radius the radius to search within, in meters | ||
* @param limit the maximum number of stops to retrieve | ||
* @return a list of the nearest stops to the specified location within the given radius | ||
*/ | ||
List<Stop> getNearestStops(Location location, int radius, int limit); | ||
|
||
/** | ||
* Retrieves the next departures from a specific stop within a given date range. | ||
* | ||
* @param stop the stop for which to retrieve departures | ||
* @param from the start date for the departures | ||
* @param until the end date for the departures (nullable) | ||
* @param limit the maximum number of departures to retrieve | ||
* @return a list of upcoming departures from the specified stop | ||
*/ | ||
List<StopTime> getNextDepartures(Stop stop, LocalDate from, @Nullable LocalDate until, int limit); | ||
|
||
/** | ||
* Retrieves possible connections between two locations at a specified time. | ||
* | ||
* @param source the starting location | ||
* @param target the destination location | ||
* @param time the time of departure or arrival | ||
* @param timeType the type of time specified (departure or arrival) | ||
* @param config additional configuration for the query | ||
* @return a list of possible connections between the source and target locations | ||
*/ | ||
List<Connection> getConnections(Location source, Location target, LocalDateTime time, TimeType timeType, | ||
ConnectionQueryConfig config); | ||
|
||
/** | ||
* Retrieves the shortest possible connection to each stop from a given departure location and time within a given | ||
* time budget or a maximum number of transfers. | ||
* | ||
* @param source the location to start the journey from | ||
* @param departureTime the time of departure | ||
* @param config additional configuration for the query | ||
* @return a map of stops to the shortest possible connection to each stop from the departure location | ||
*/ | ||
Map<Stop, Connection> isoline(Location source, LocalDateTime departureTime, ConnectionQueryConfig config); | ||
|
||
/** | ||
* Retrieves a stop by its ID. | ||
* | ||
* @param stopId the ID of the stop to retrieve | ||
* @return the stop with the specified ID | ||
* @throws StopNotFoundException if no stop with the specified ID is found | ||
*/ | ||
Stop getStopById(String stopId) throws StopNotFoundException; | ||
|
||
/** | ||
* Retrieves a trip by its ID. | ||
* | ||
* @param tripId the ID of the trip to retrieve | ||
* @return the trip with the specified ID | ||
* @throws TripNotFoundException if no trip with the specified ID is found | ||
*/ | ||
Trip getTripById(String tripId) throws TripNotFoundException; | ||
|
||
/** | ||
* Retrieves a route by its ID. | ||
* | ||
* @param routeId the ID of the route to retrieve | ||
* @return the route with the specified ID | ||
* @throws RouteNotFoundException if no route with the specified ID is found | ||
*/ | ||
Route getRouteById(String routeId) throws RouteNotFoundException; | ||
|
||
} |
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,20 @@ | ||
package ch.naviqore.service; | ||
|
||
/** | ||
* A public transit route (also called transit line). | ||
*/ | ||
public interface Route { | ||
|
||
String getId(); | ||
|
||
String getName(); | ||
|
||
String getShortName(); | ||
|
||
String getDescription(); | ||
|
||
String getRouteType(); | ||
|
||
String getAgency(); | ||
|
||
} |
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,8 @@ | ||
package ch.naviqore.service; | ||
|
||
public enum SearchType { | ||
STARTS_WITH, | ||
ENDS_WITH, | ||
CONTAINS, | ||
EXACT | ||
} |
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,11 @@ | ||
package ch.naviqore.service; | ||
|
||
public interface Stop extends Location { | ||
|
||
String getId(); | ||
|
||
String getName(); | ||
|
||
Location getLocation(); | ||
|
||
} |
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,15 @@ | ||
package ch.naviqore.service; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public interface StopTime { | ||
|
||
Trip getTrip(); | ||
|
||
Stop getStop(); | ||
|
||
LocalDateTime getArrivalTime(); | ||
|
||
LocalDateTime getDepartureTime(); | ||
|
||
} |
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.service; | ||
|
||
public enum TimeType { | ||
ARRIVAL, | ||
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,18 @@ | ||
package ch.naviqore.service; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* A trip starts on a public transit route an follows its stop sequence. | ||
* <p> | ||
* Note: There can be trips with different stop sequences which belong to the same route. | ||
*/ | ||
public interface Trip { | ||
|
||
String getId(); | ||
|
||
Route getRoute(); | ||
|
||
List<StopTime> getStopTimes(); | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/ch/naviqore/service/config/ConnectionQueryConfig.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,13 @@ | ||
package ch.naviqore.service.config; | ||
|
||
public interface ConnectionQueryConfig { | ||
|
||
int getMaximumWalkingDuration(); | ||
|
||
int getMinimumTransferDuration(); | ||
|
||
int getMaximumTransferNumber(); | ||
|
||
int getMaximumTravelTime(); | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/ch/naviqore/service/exception/NotFoundException.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,9 @@ | ||
package ch.naviqore.service.exception; | ||
|
||
public class NotFoundException extends Exception { | ||
|
||
public NotFoundException(String type, String id) { | ||
super(type + " " + id + " not found."); | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/ch/naviqore/service/exception/RouteNotFoundException.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,9 @@ | ||
package ch.naviqore.service.exception; | ||
|
||
public class RouteNotFoundException extends NotFoundException { | ||
|
||
public RouteNotFoundException(String id) { | ||
super("Route", id); | ||
} | ||
|
||
} |
Oops, something went wrong.