Skip to content

Commit

Permalink
Move classes to top level
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed Oct 6, 2023
1 parent d918c4e commit 3ce18cc
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 58 deletions.
3 changes: 3 additions & 0 deletions src/main/java/org/opentripplanner/client/model/Agency.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package org.opentripplanner.client.model;

public record Agency(String name) {}
3 changes: 3 additions & 0 deletions src/main/java/org/opentripplanner/client/model/Currency.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package org.opentripplanner.client.model;

public record Currency(int digits, String code) {}
18 changes: 18 additions & 0 deletions src/main/java/org/opentripplanner/client/model/FareProductUse.java
Original file line number Diff line number Diff line change
@@ -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) {}
}
}
20 changes: 20 additions & 0 deletions src/main/java/org/opentripplanner/client/model/Itinerary.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.opentripplanner.client.model;

import java.util.List;

public record Itinerary(List<Leg> 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<Leg> transitLegs() {
return legs.stream().filter(Leg::isTransit).toList();
}
}
25 changes: 25 additions & 0 deletions src/main/java/org/opentripplanner/client/model/Leg.java
Original file line number Diff line number Diff line change
@@ -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<FareProductUse> fareProducts) {

/**
* Is this leg using public transport?
*/
public boolean isTransit() {
return mode.isTransit();
}
}
5 changes: 5 additions & 0 deletions src/main/java/org/opentripplanner/client/model/Money.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.opentripplanner.client.model;

import java.math.BigDecimal;

public record Money(BigDecimal amount, Currency currency) {}
57 changes: 0 additions & 57 deletions src/main/java/org/opentripplanner/client/model/TripPlan.java
Original file line number Diff line number Diff line change
@@ -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<Itinerary> itineraries) {

public record Itinerary(List<Leg> 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<Leg> 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<FareProductUse> 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<Itinerary> transitItineraries() {
return itineraries.stream().filter(Itinerary::hasTransit).toList();
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/queries/routes.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@ query {
routes {
shortName
mode
agency {
name
}
}
}
2 changes: 1 addition & 1 deletion src/test/java/org/opentripplanner/IntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 3ce18cc

Please sign in to comment.