Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When using ScheduledTransitLeg's copy builder, also copy alerts #6368

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -98,6 +98,7 @@ protected ScheduledTransitLeg(ScheduledTransitLegBuilder<?> builder) {
getDistanceFromCoordinates(
List.of(transitLegCoordinates.getFirst(), transitLegCoordinates.getLast())
);
this.transitAlerts.addAll(builder.alerts());
}

public ZoneId getZoneId() {
Original file line number Diff line number Diff line change
@@ -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;
@@ -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() {}

@@ -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) {
@@ -159,6 +164,10 @@ public Float accessibilityScore() {
return accessibilityScore;
}

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

public ScheduledTransitLeg build() {
return new ScheduledTransitLeg(this);
}
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;
leonardehrenfried marked this conversation as resolved.
Show resolved Hide resolved
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();
@@ -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());
}
}