Skip to content

Commit

Permalink
Changes based on review comments and small optimization.
Browse files Browse the repository at this point in the history
  • Loading branch information
VillePihlava committed Dec 13, 2024
1 parent 95e9ca7 commit df64c5a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.google.common.collect.Multimap;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.opentripplanner.ext.flex.trip.FlexTrip;
import org.opentripplanner.model.PathTransfer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public static RaptorTransferIndex create(
StreetMode mode = request.mode();

for (int i = 0; i < transfersByStopIndex.size(); i++) {
forwardTransfers.add(new ArrayList<>());
reversedTransfers.add(new ArrayList<>());
}

Expand All @@ -43,14 +42,14 @@ public static RaptorTransferIndex create(
var transfers = transfersByStopIndex
.get(fromStop)
.stream()
.filter(transfer -> transfer.getModes().contains(mode))
.filter(transfer -> transfer.allowsMode(mode))
.flatMap(s -> s.asRaptorTransfer(request).stream())
.collect(
toMap(RaptorTransfer::stop, Function.identity(), (a, b) -> a.c1() < b.c1() ? a : b)
)
.values();

forwardTransfers.get(fromStop).addAll(transfers);
forwardTransfers.add(new ArrayList<>(transfers));

for (RaptorTransfer forwardTransfer : transfers) {
reversedTransfers
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package org.opentripplanner.routing.algorithm.raptoradapter.transit;

import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -35,20 +34,20 @@ public class Transfer {

private final List<Edge> edges;

private final ImmutableSet<StreetMode> modes;
private final Set<StreetMode> modes;

public Transfer(int toStop, List<Edge> edges, EnumSet<StreetMode> modes) {
this.toStop = toStop;
this.edges = edges;
this.distanceMeters = (int) edges.stream().mapToDouble(Edge::getDistanceMeters).sum();
this.modes = Sets.immutableEnumSet(modes);
this.modes = Collections.unmodifiableSet(modes);
}

public Transfer(int toStopIndex, int distanceMeters, EnumSet<StreetMode> modes) {
this.toStop = toStopIndex;
this.distanceMeters = distanceMeters;
this.edges = null;
this.modes = Sets.immutableEnumSet(modes);
this.modes = Collections.unmodifiableSet(modes);
}

public List<Coordinate> getCoordinates() {
Expand Down Expand Up @@ -76,8 +75,8 @@ public List<Edge> getEdges() {
return edges;
}

public ImmutableSet<StreetMode> getModes() {
return modes;
public boolean allowsMode(StreetMode mode) {
return modes.contains(mode);
}

public Optional<RaptorTransfer> asRaptorTransfer(StreetSearchRequest request) {
Expand Down

0 comments on commit df64c5a

Please sign in to comment.