From 3ce18ccbdfdd03676f751dd25b7536c110180217 Mon Sep 17 00:00:00 2001 From: Leonard Ehrenfried Date: Fri, 6 Oct 2023 17:36:27 +0200 Subject: [PATCH] Move classes to top level --- .../opentripplanner/client/model/Agency.java | 3 + .../client/model/Currency.java | 3 + .../client/model/FareProductUse.java | 18 ++++++ .../client/model/Itinerary.java | 20 +++++++ .../org/opentripplanner/client/model/Leg.java | 25 ++++++++ .../opentripplanner/client/model/Money.java | 5 ++ .../client/model/TripPlan.java | 57 ------------------- src/main/resources/queries/routes.graphql | 3 + .../org/opentripplanner/IntegrationTest.java | 2 +- 9 files changed, 78 insertions(+), 58 deletions(-) create mode 100644 src/main/java/org/opentripplanner/client/model/Agency.java create mode 100644 src/main/java/org/opentripplanner/client/model/Currency.java create mode 100644 src/main/java/org/opentripplanner/client/model/FareProductUse.java create mode 100644 src/main/java/org/opentripplanner/client/model/Itinerary.java create mode 100644 src/main/java/org/opentripplanner/client/model/Leg.java create mode 100644 src/main/java/org/opentripplanner/client/model/Money.java diff --git a/src/main/java/org/opentripplanner/client/model/Agency.java b/src/main/java/org/opentripplanner/client/model/Agency.java new file mode 100644 index 0000000..02476d5 --- /dev/null +++ b/src/main/java/org/opentripplanner/client/model/Agency.java @@ -0,0 +1,3 @@ +package org.opentripplanner.client.model; + +public record Agency(String name) {} diff --git a/src/main/java/org/opentripplanner/client/model/Currency.java b/src/main/java/org/opentripplanner/client/model/Currency.java new file mode 100644 index 0000000..184ee32 --- /dev/null +++ b/src/main/java/org/opentripplanner/client/model/Currency.java @@ -0,0 +1,3 @@ +package org.opentripplanner.client.model; + +public record Currency(int digits, String code) {} diff --git a/src/main/java/org/opentripplanner/client/model/FareProductUse.java b/src/main/java/org/opentripplanner/client/model/FareProductUse.java new file mode 100644 index 0000000..5fc7442 --- /dev/null +++ b/src/main/java/org/opentripplanner/client/model/FareProductUse.java @@ -0,0 +1,18 @@ +package org.opentripplanner.client.model; + +import jakarta.annotation.Nullable; + +public record FareProductUse(String id, FareProduct product) { + + public record FareProduct( + String id, + String name, + Money price, + @Nullable FareProduct.RiderCategory riderCategory, + @Nullable FareProduct.FareMedium medium) { + + public record RiderCategory(String id, String name) {} + + public record FareMedium(String id, String name) {} + } +} diff --git a/src/main/java/org/opentripplanner/client/model/Itinerary.java b/src/main/java/org/opentripplanner/client/model/Itinerary.java new file mode 100644 index 0000000..fdff80b --- /dev/null +++ b/src/main/java/org/opentripplanner/client/model/Itinerary.java @@ -0,0 +1,20 @@ +package org.opentripplanner.client.model; + +import java.util.List; + +public record Itinerary(List legs) { + + /** + * Does this itinerary contain any legs that contain public transport? + */ + public boolean hasTransit() { + return legs.stream().anyMatch(Leg::isTransit); + } + + /** + * @return All legs that are using public transport. + */ + public List transitLegs() { + return legs.stream().filter(Leg::isTransit).toList(); + } +} diff --git a/src/main/java/org/opentripplanner/client/model/Leg.java b/src/main/java/org/opentripplanner/client/model/Leg.java new file mode 100644 index 0000000..7a4d9b5 --- /dev/null +++ b/src/main/java/org/opentripplanner/client/model/Leg.java @@ -0,0 +1,25 @@ +package org.opentripplanner.client.model; + +import java.time.Duration; +import java.time.OffsetDateTime; +import java.util.List; +import org.opentripplanner.client.model.TripPlan.Place; + +public record Leg( + Place from, + Place to, + OffsetDateTime startTime, + OffsetDateTime endTime, + LegMode mode, + Duration duration, + double distance, + Route route, + List fareProducts) { + + /** + * Is this leg using public transport? + */ + public boolean isTransit() { + return mode.isTransit(); + } +} diff --git a/src/main/java/org/opentripplanner/client/model/Money.java b/src/main/java/org/opentripplanner/client/model/Money.java new file mode 100644 index 0000000..8105c28 --- /dev/null +++ b/src/main/java/org/opentripplanner/client/model/Money.java @@ -0,0 +1,5 @@ +package org.opentripplanner.client.model; + +import java.math.BigDecimal; + +public record Money(BigDecimal amount, Currency currency) {} diff --git a/src/main/java/org/opentripplanner/client/model/TripPlan.java b/src/main/java/org/opentripplanner/client/model/TripPlan.java index c240457..0cac17a 100644 --- a/src/main/java/org/opentripplanner/client/model/TripPlan.java +++ b/src/main/java/org/opentripplanner/client/model/TripPlan.java @@ -1,68 +1,11 @@ package org.opentripplanner.client.model; -import jakarta.annotation.Nullable; -import java.math.BigDecimal; -import java.time.Duration; -import java.time.OffsetDateTime; import java.util.List; public record TripPlan(List itineraries) { - public record Itinerary(List legs) { - - /** Does this itinerary contain any legs that contain public transport? */ - public boolean hasTransit() { - return legs.stream().anyMatch(Leg::isTransit); - } - - /** - * @return All legs that are using public transport. - */ - public List transitLegs() { - return legs.stream().filter(Leg::isTransit).toList(); - } - } - public record Place(String name) {} - public record Route(String shortName, String longName, Agency agency) {} - - public record Agency(String name) {} - - public record Currency(int digits, String code) {} - - public record Money(BigDecimal amount, Currency currency) {} - - public record RiderCategory(String id, String name) {} - - public record FareMedium(String id, String name) {} - - public record FareProduct( - String id, - String name, - Money price, - @Nullable RiderCategory riderCategory, - @Nullable FareMedium medium) {} - - public record FareProductUse(String id, FareProduct product) {} - - public record Leg( - Place from, - Place to, - OffsetDateTime startTime, - OffsetDateTime endTime, - LegMode mode, - Duration duration, - double distance, - Route route, - List fareProducts) { - - /** Is this leg using public transport? */ - public boolean isTransit() { - return mode.isTransit(); - } - } - /** Returns a list of all itineraries that contain public transport. */ public List transitItineraries() { return itineraries.stream().filter(Itinerary::hasTransit).toList(); diff --git a/src/main/resources/queries/routes.graphql b/src/main/resources/queries/routes.graphql index d761580..933735f 100644 --- a/src/main/resources/queries/routes.graphql +++ b/src/main/resources/queries/routes.graphql @@ -2,5 +2,8 @@ query { routes { shortName mode + agency { + name + } } } \ No newline at end of file diff --git a/src/test/java/org/opentripplanner/IntegrationTest.java b/src/test/java/org/opentripplanner/IntegrationTest.java index a6f4c9e..52db9c7 100644 --- a/src/test/java/org/opentripplanner/IntegrationTest.java +++ b/src/test/java/org/opentripplanner/IntegrationTest.java @@ -14,7 +14,7 @@ import org.opentripplanner.client.OtpApiClient; import org.opentripplanner.client.model.Coordinate; import org.opentripplanner.client.model.RequestMode; -import org.opentripplanner.client.model.TripPlan.FareProductUse; +import org.opentripplanner.client.model.FareProductUse; import org.opentripplanner.client.parameters.TripPlanParameters; import org.opentripplanner.client.parameters.TripPlanParameters.SearchDirection; import org.slf4j.Logger;