Skip to content

Commit

Permalink
Fix ScheduledTransitAlertBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed Jan 9, 2025
1 parent 0fb152d commit 1bfc833
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ protected ScheduledTransitLeg(ScheduledTransitLegBuilder<?> builder) {
getDistanceFromCoordinates(
List.of(transitLegCoordinates.getFirst(), transitLegCoordinates.getLast())
);
this.transitAlerts.addAll(builder.alerts());
}

public ZoneId getZoneId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.HashSet;
import java.util.Set;
import org.opentripplanner.model.transfer.ConstrainedTransfer;
import org.opentripplanner.routing.alertpatch.TransitAlert;
import org.opentripplanner.transit.model.network.TripPattern;
import org.opentripplanner.transit.model.timetable.TripOnServiceDate;
import org.opentripplanner.transit.model.timetable.TripTimes;
Expand All @@ -23,6 +26,7 @@ public class ScheduledTransitLegBuilder<B extends ScheduledTransitLegBuilder<B>>
private ConstrainedTransfer transferToNextLeg;
private int generalizedCost;
private Float accessibilityScore;
private Set<TransitAlert> alerts = new HashSet<>();

public ScheduledTransitLegBuilder() {}

Expand All @@ -40,6 +44,7 @@ public ScheduledTransitLegBuilder(ScheduledTransitLeg original) {
generalizedCost = original.getGeneralizedCost();
accessibilityScore = original.accessibilityScore();
zoneId = original.getZoneId();
alerts = original.getTransitAlerts();
}

public B withTripTimes(TripTimes tripTimes) {
Expand Down Expand Up @@ -159,6 +164,10 @@ public Float accessibilityScore() {
return accessibilityScore;
}

public Set<TransitAlert> alerts() {
return alerts;
}

public ScheduledTransitLeg build() {
return new ScheduledTransitLeg(this);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
package org.opentripplanner.model.plan;

import static com.google.common.truth.Truth.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.opentripplanner.transit.model._data.TimetableRepositoryForTest.id;

import java.time.LocalDate;
import java.util.Set;
import org.junit.jupiter.api.Test;
import org.opentripplanner._support.time.ZoneIds;
import org.opentripplanner.framework.i18n.I18NString;
import org.opentripplanner.routing.alertpatch.TransitAlert;
import org.opentripplanner.transit.model._data.TimetableRepositoryForTest;
import org.opentripplanner.transit.model.basic.TransitMode;

class ScheduledTransitLegBuilderTest {

private static final TransitAlert ALERT = TransitAlert
.of(id("alert"))
.withDescriptionText(I18NString.of("alert"))
.build();

@Test
void transferZoneId() {
var pattern = TimetableRepositoryForTest.of().pattern(TransitMode.BUS).build();
Expand All @@ -28,4 +38,24 @@ void transferZoneId() {

assertEquals(ZoneIds.BERLIN, withScore.getZoneId());
}

@Test
void alerts() {
var pattern = TimetableRepositoryForTest.of().pattern(TransitMode.BUS).build();
var leg = new ScheduledTransitLegBuilder<>()
.withZoneId(ZoneIds.BERLIN)
.withServiceDate(LocalDate.of(2023, 11, 15))
.withTripPattern(pattern)
.withBoardStopIndexInPattern(0)
.withAlightStopIndexInPattern(1)
.build();

leg.addAlert(ALERT);

var newLeg = new ScheduledTransitLegBuilder<>(leg);

var withScore = newLeg.withAccessibilityScore(4f).build();

assertEquals(Set.of(ALERT), withScore.getTransitAlerts());
}
}

0 comments on commit 1bfc833

Please sign in to comment.