From 984d34eeebfdacb8469e89705b83bfb10fd9965a Mon Sep 17 00:00:00 2001 From: Ville Pihlava Date: Mon, 9 Dec 2024 14:33:37 +0200 Subject: [PATCH] Change how EnumSet is copied and make EnumSet immutable in Transfer. --- .../java/org/opentripplanner/model/PathTransfer.java | 2 +- .../algorithm/raptoradapter/transit/Transfer.java | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/application/src/main/java/org/opentripplanner/model/PathTransfer.java b/application/src/main/java/org/opentripplanner/model/PathTransfer.java index a6b66548e64..01aa9af02f5 100644 --- a/application/src/main/java/org/opentripplanner/model/PathTransfer.java +++ b/application/src/main/java/org/opentripplanner/model/PathTransfer.java @@ -57,7 +57,7 @@ public List getEdges() { } public EnumSet getModes() { - return modes.clone(); + return EnumSet.copyOf(modes); } public PathTransfer withAddedMode(StreetMode mode) { diff --git a/application/src/main/java/org/opentripplanner/routing/algorithm/raptoradapter/transit/Transfer.java b/application/src/main/java/org/opentripplanner/routing/algorithm/raptoradapter/transit/Transfer.java index 2440321ab1f..648343b9b0f 100644 --- a/application/src/main/java/org/opentripplanner/routing/algorithm/raptoradapter/transit/Transfer.java +++ b/application/src/main/java/org/opentripplanner/routing/algorithm/raptoradapter/transit/Transfer.java @@ -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; @@ -33,20 +35,20 @@ public class Transfer { private final List edges; - private final EnumSet modes; + private final ImmutableSet modes; public Transfer(int toStop, List edges, EnumSet 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 modes) { this.toStop = toStopIndex; this.distanceMeters = distanceMeters; this.edges = null; - this.modes = modes; + this.modes = Sets.immutableEnumSet(modes); } public List getCoordinates() { @@ -74,8 +76,8 @@ public List getEdges() { return edges; } - public EnumSet getModes() { - return modes.clone(); + public ImmutableSet getModes() { + return modes; } public Optional asRaptorTransfer(StreetSearchRequest request) {