Skip to content

Commit bf0d9a9

Browse files
Rework strategy for default time values
1 parent 61ae93c commit bf0d9a9

File tree

4 files changed

+34
-8
lines changed

4 files changed

+34
-8
lines changed

application/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@
306306
<dependency>
307307
<groupId>org.onebusaway</groupId>
308308
<artifactId>onebusaway-gtfs</artifactId>
309-
<version>11.2.0</version>
309+
<version>11.2.1</version>
310310
</dependency>
311311
<!-- Processing is used for the debug GUI (though we could probably use just Java2D) -->
312312
<dependency>

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
import com.google.common.collect.ArrayListMultimap;
44
import com.google.common.collect.Multimap;
5+
import java.time.LocalTime;
56
import java.util.Collection;
7+
import java.util.Objects;
68
import org.opentripplanner.core.model.id.FeedScopedId;
79
import org.opentripplanner.ext.fares.model.Timeframe;
810

@@ -22,8 +24,9 @@ public Timeframe map(org.onebusaway.gtfs.model.Timeframe rhs) {
2224
);
2325
var t = Timeframe.of()
2426
.withServiceId(serviceId)
25-
.withStart(rhs.getStartTime())
26-
.withEnd(rhs.getEndTime())
27+
.withStart(Objects.requireNonNullElse(rhs.getStartTime(), LocalTime.MIN))
28+
// LocalTime.MAX is 23:59.9999999
29+
.withEnd(Objects.requireNonNullElse(rhs.getEndTime(), LocalTime.MAX))
2730
.build();
2831
var groupId = idFactory.createId(rhs.getTimeframeGroupId(), "timeframe's group id");
2932
mappedTimeframes.put(groupId, t);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package org.onebusaway.gtfs.model;
2+
3+
public class AgencyAndIdFactory {
4+
5+
private static final String AGENCY_ID = "oba";
6+
7+
public static AgencyAndId obaId(String id) {
8+
return new AgencyAndId(AGENCY_ID, id);
9+
}
10+
}

application/src/ext-test/java/org/opentripplanner/gtfs/mapping/TimeframeMapperTest.java renamed to application/src/test/java/org/opentripplanner/gtfs/mapping/TimeframeMapperTest.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,43 @@
11
package org.opentripplanner.gtfs.mapping;
22

33
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.onebusaway.gtfs.model.AgencyAndIdFactory.obaId;
45

56
import java.time.LocalTime;
67
import org.junit.jupiter.api.Test;
7-
import org.onebusaway.gtfs.model.AgencyAndId;
88
import org.onebusaway.gtfs.model.Timeframe;
99

1010
class TimeframeMapperTest {
1111

12-
private static final IdFactory A = new IdFactory("A");
12+
private static final IdFactory ID_FACTORY = new IdFactory("A");
1313
public static final LocalTime START = LocalTime.NOON;
1414
public static final LocalTime END = START.plusHours(1);
1515

1616
@Test
1717
void map() {
1818
var tf = new Timeframe();
19-
tf.setTimeframeGroupId(new AgencyAndId("a", "1"));
20-
tf.setId(new AgencyAndId("a", "1"));
19+
tf.setTimeframeGroupId(obaId("1"));
20+
tf.setId(obaId("1"));
2121
tf.setStartTime(START);
2222
tf.setEndTime(END);
2323
tf.setServiceId("s1");
2424

25-
var mapper = new TimeframeMapper(A);
25+
var mapper = new TimeframeMapper(ID_FACTORY);
2626
var mapped = mapper.map(tf);
2727
assertEquals(START, mapped.startTime());
2828
assertEquals(END, mapped.endTime());
2929
}
30+
31+
@Test
32+
void noValues() {
33+
var tf = new Timeframe();
34+
tf.setTimeframeGroupId(obaId("1"));
35+
tf.setId(obaId("1"));
36+
tf.setServiceId("s1");
37+
38+
var mapper = new TimeframeMapper(ID_FACTORY);
39+
var mapped = mapper.map(tf);
40+
assertEquals(LocalTime.MIN, mapped.startTime());
41+
assertEquals(LocalTime.MAX, mapped.endTime());
42+
}
3043
}

0 commit comments

Comments
 (0)