Skip to content

Commit cea28d4

Browse files
Use more FeedScopedIds
1 parent 67e519c commit cea28d4

File tree

6 files changed

+23
-19
lines changed

6 files changed

+23
-19
lines changed

application/src/ext-test/java/org/opentripplanner/ext/fares/impl/GtfsFaresV2ServiceTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ class GtfsFaresV2ServiceTest implements PlanTestConstants {
9999
Place OUTER_ZONE_STOP = Place.forStop(
100100
testModel.stop("outer city stop").withCoordinate(2, 2).build()
101101
);
102-
String INNER_ZONE = "inner-zone";
103-
String OUTER_ZONE = "outer-zone";
102+
FeedScopedId INNER_ZONE = id("inner-zone");
103+
FeedScopedId OUTER_ZONE = id("outer-zone");
104104

105105
GtfsFaresV2Service service = new GtfsFaresV2Service(
106106
List.of(

application/src/ext/java/org/opentripplanner/ext/fares/impl/DefaultFareServiceFactory.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class DefaultFareServiceFactory implements FareServiceFactory {
3838
private final List<FareTransferRule> fareTransferRules = new ArrayList<>();
3939

4040
// mapping the stop ids to area ids. one stop can be in several areas.
41-
private final Multimap<FeedScopedId, String> stopAreas = ArrayListMultimap.create();
41+
private final Multimap<FeedScopedId, FeedScopedId> stopAreas = ArrayListMultimap.create();
4242

4343
@Override
4444
public FareService makeFareService() {

application/src/ext/java/org/opentripplanner/ext/fares/impl/GtfsFaresV2Service.java

+11-7
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ public final class GtfsFaresV2Service implements Serializable {
3232
private static final Logger LOG = LoggerFactory.getLogger(GtfsFaresV2Service.class);
3333
private final List<FareLegRule> legRules;
3434
private final List<FareTransferRule> transferRules;
35-
private final Multimap<FeedScopedId, String> stopAreas;
35+
private final Multimap<FeedScopedId, FeedScopedId> stopAreas;
3636
private final Set<FeedScopedId> networksWithRules;
37-
private final Set<String> fromAreasWithRules;
38-
private final Set<String> toAreasWithRules;
37+
private final Set<FeedScopedId> fromAreasWithRules;
38+
private final Set<FeedScopedId> toAreasWithRules;
3939

4040
public GtfsFaresV2Service(
4141
List<FareLegRule> legRules,
4242
List<FareTransferRule> fareTransferRules,
43-
Multimap<FeedScopedId, String> stopAreas
43+
Multimap<FeedScopedId, FeedScopedId> stopAreas
4444
) {
4545
this.legRules = legRules;
4646
this.transferRules = fareTransferRules;
@@ -72,9 +72,9 @@ public ProductResult getProducts(Itinerary itinerary) {
7272
return new ProductResult(coveringItinerary, allLegProducts);
7373
}
7474

75-
private static Set<String> findAreasWithRules(
75+
private static Set<FeedScopedId> findAreasWithRules(
7676
List<FareLegRule> legRules,
77-
Function<FareLegRule, String> getArea
77+
Function<FareLegRule, FeedScopedId> getArea
7878
) {
7979
return legRules.stream().map(getArea).filter(Objects::nonNull).collect(Collectors.toSet());
8080
}
@@ -207,7 +207,11 @@ private Optional<FareLegRule> getFareLegRuleByGroupId(FeedScopedId groupId) {
207207
return legRules.stream().filter(lr -> groupId.equals(lr.legGroupId())).findAny();
208208
}
209209

210-
private boolean matchesArea(StopLocation stop, String areaId, Set<String> areasWithRules) {
210+
private boolean matchesArea(
211+
StopLocation stop,
212+
FeedScopedId areaId,
213+
Set<FeedScopedId> areasWithRules
214+
) {
211215
var stopAreas = this.stopAreas.get(stop.getId());
212216
return (
213217
(isNull(areaId) && stopAreas.stream().noneMatch(areasWithRules::contains)) ||

application/src/ext/java/org/opentripplanner/ext/fares/model/FareLegRule.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ public record FareLegRule(
1212
FeedScopedId id,
1313
@Nullable FeedScopedId legGroupId,
1414
@Nullable FeedScopedId networkId,
15-
@Nullable String fromAreaId,
16-
@Nullable String toAreaId,
15+
@Nullable FeedScopedId fromAreaId,
16+
@Nullable FeedScopedId toAreaId,
1717
@Nullable FareDistance fareDistance,
1818
Collection<FareProduct> fareProducts
1919
) {

application/src/ext/java/org/opentripplanner/ext/fares/model/FareLegRuleBuilder.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ public class FareLegRuleBuilder {
1313
private final Collection<FareProduct> fareProducts;
1414
private FeedScopedId legGroupId;
1515
private FeedScopedId networkId;
16-
private String fromAreaId;
16+
private FeedScopedId fromAreaId;
17+
private FeedScopedId toAreaId;
1718
private FareDistance fareDistance = null;
18-
private String toAreaId;
1919

2020
public FareLegRuleBuilder(FeedScopedId id, Collection<FareProduct> products) {
2121
this.id = id;
@@ -32,7 +32,7 @@ public FareLegRuleBuilder withNetworkId(FeedScopedId networkId) {
3232
return this;
3333
}
3434

35-
public FareLegRuleBuilder withFromAreaId(String fromAreaId) {
35+
public FareLegRuleBuilder withFromAreaId(FeedScopedId fromAreaId) {
3636
this.fromAreaId = fromAreaId;
3737
return this;
3838
}
@@ -42,7 +42,7 @@ public FareLegRuleBuilder withFareDistance(FareDistance fareDistance) {
4242
return this;
4343
}
4444

45-
public FareLegRuleBuilder withToAreaId(String toAreaId) {
45+
public FareLegRuleBuilder withToAreaId(FeedScopedId toAreaId) {
4646
this.toAreaId = toAreaId;
4747
return this;
4848
}

application/src/main/java/org/opentripplanner/gtfs/mapping/FareLegRuleMapper.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public Collection<FareLegRule> map(
4343
var ruleId = new FeedScopedId(fareProductId.getFeedId(), r.getId());
4444
return FareLegRule.of(ruleId, productsForRule)
4545
.withLegGroupId(idFactory.toId(r.getLegGroupId()))
46-
.withNetworkId(FeedScopedId.ofNullable(fareProductId.getFeedId(), r.getNetworkId()))
46+
.withNetworkId(idFactory.id(r.getNetworkId()))
4747
.withFromAreaId(areaId(r.getFromArea()))
4848
.withToAreaId(areaId(r.getToArea()))
4949
.withFareDistance(fareDistance)
@@ -62,11 +62,11 @@ public Collection<FareLegRule> map(
6262
.toList();
6363
}
6464

65-
private static String areaId(@Nullable org.onebusaway.gtfs.model.Area area) {
65+
private FeedScopedId areaId(@Nullable org.onebusaway.gtfs.model.Area area) {
6666
if (area == null) {
6767
return null;
6868
} else {
69-
return area.getAreaId();
69+
return idFactory.id(area.getAreaId());
7070
}
7171
}
7272

0 commit comments

Comments
 (0)