Skip to content

Commit

Permalink
Change how EnumSet is copied and make EnumSet immutable in Transfer.
Browse files Browse the repository at this point in the history
  • Loading branch information
VillePihlava committed Dec 9, 2024
1 parent 012f149 commit 984d34e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public List<Edge> getEdges() {
}

public EnumSet<StreetMode> getModes() {
return modes.clone();
return EnumSet.copyOf(modes);
}

public PathTransfer withAddedMode(StreetMode mode) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
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.EnumSet;
Expand Down Expand Up @@ -33,20 +35,20 @@ public class Transfer {

private final List<Edge> edges;

private final EnumSet<StreetMode> modes;
private final ImmutableSet<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 = modes;
this.modes = Sets.immutableEnumSet(modes);
}

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

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

public EnumSet<StreetMode> getModes() {
return modes.clone();
public ImmutableSet<StreetMode> getModes() {
return modes;
}

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

0 comments on commit 984d34e

Please sign in to comment.