File tree Expand file tree Collapse file tree
ext/java/org/opentripplanner/ext/fares/model
main/java/org/opentripplanner/gtfs/mapping
test/java/org/opentripplanner/gtfs/mapping Expand file tree Collapse file tree Original file line number Diff line number Diff line change 88import javax .annotation .Nullable ;
99import org .opentripplanner .core .model .id .FeedScopedId ;
1010import org .opentripplanner .model .fare .FareProduct ;
11+ import org .opentripplanner .utils .lang .IntUtils ;
1112import org .opentripplanner .utils .tostring .ToStringBuilder ;
1213
1314public final class FareTransferRule implements Serializable {
@@ -33,7 +34,11 @@ public final class FareTransferRule implements Serializable {
3334 this .fareProducts = List .copyOf (b .fareProducts ());
3435 this .fromLegGroup = b .fromLegGroup ();
3536 this .toLegGroup = b .toLegGroup ();
36- this .transferCount = b .transferCount ();
37+ this .transferCount = IntUtils .requireInRange (
38+ b .transferCount (),
39+ UNLIMITED_TRANSFERS ,
40+ Integer .MAX_VALUE
41+ );
3742 this .timeLimit = b .timeLimit ();
3843 }
3944
Original file line number Diff line number Diff line change 1212
1313class FareTransferRuleMapper {
1414
15- public final int MISSING_VALUE = -999 ;
16-
1715 private final IdFactory idFactory ;
1816 private final FareProductMapper fareProductMapper ;
1917
@@ -36,9 +34,11 @@ private FareTransferRule doMap(org.onebusaway.gtfs.model.FareTransferRule rhs) {
3634 .withId (idFactory .createId (rhs .getId (), "fare transfer rule" ))
3735 .withFromLegGroup (idFactory .createNullableId (rhs .getFromLegGroupId ()))
3836 .withToLegGroup (idFactory .createNullableId (rhs .getToLegGroupId ()))
39- .withTransferCount (rhs .getTransferCount ())
4037 .withFareProducts (products );
41- if (rhs .getDurationLimit () != MISSING_VALUE ) {
38+ if (rhs .isTransferCountSet ()) {
39+ builder .withTransferCount (rhs .getTransferCount ());
40+ }
41+ if (rhs .isDurationLimitSet ()) {
4242 var duration = Duration .ofSeconds (rhs .getDurationLimit ());
4343 var type = mapLimitType (rhs .getDurationLimitType ());
4444 builder .withTimeLimit (type , duration );
Original file line number Diff line number Diff line change @@ -99,6 +99,37 @@ void ruleWithoutProductIsFree() {
9999 assertTrue (transferRule .isFree ());
100100 }
101101
102+ @ Test
103+ void defaultTransferCount () {
104+ var rule = new FareTransferRule ();
105+ rule .setFromLegGroupId (groupId1 );
106+ rule .setToLegGroupId (groupId2 );
107+
108+ var transferRule = map (fareProduct (), rule );
109+ assertTrue (transferRule .unlimitedTransfers ());
110+ }
111+
112+ @ Test
113+ void transferCount () {
114+ var rule = new FareTransferRule ();
115+ rule .setFromLegGroupId (groupId1 );
116+ rule .setToLegGroupId (groupId2 );
117+ rule .setTransferCount (2 );
118+
119+ var transferRule = map (fareProduct (), rule );
120+ assertFalse (transferRule .unlimitedTransfers ());
121+ }
122+
123+ @ Test
124+ void invalidTransferCount () {
125+ var rule = new FareTransferRule ();
126+ rule .setFromLegGroupId (groupId1 );
127+ rule .setToLegGroupId (groupId2 );
128+ rule .setTransferCount (-2 );
129+
130+ assertThrows (IllegalArgumentException .class , () -> map (fareProduct (), rule ));
131+ }
132+
102133 private FareProduct fareProduct () {
103134 var fareProduct = new FareProduct ();
104135 fareProduct .setId (id );
You can’t perform that action at this time.
0 commit comments