Skip to content

Commit 32f60b6

Browse files
anisometropiemultun
authored andcommitted
use static initialiser for errors hashmap
1 parent 7f23b96 commit 32f60b6

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

core/src/main/java/fr/sncf/osrd/api/pathfinding/PathfindingRoutesEndpoint.java

+10-7
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,16 @@ public class PathfindingRoutesEndpoint implements Take {
4040
public static final String PATH_FINDING_ELECTRIFICATION_ERROR =
4141
"No path could be found after loading Electrification constraints";
4242

43+
static {
44+
constraints.put(LoadingGaugeConstraints.class, PATH_FINDING_GAUGE_ERROR);
45+
constraints.put(ElectrificationConstraints.class, PATH_FINDING_ELECTRIFICATION_ERROR);
46+
}
47+
4348
/**
4449
* constructor
4550
*/
4651
public PathfindingRoutesEndpoint(InfraManager infraHandler) {
4752
this.infraManager = infraHandler;
48-
constraints.put(LoadingGaugeConstraints.class, PATH_FINDING_GAUGE_ERROR);
49-
constraints.put(ElectrificationConstraints.class, PATH_FINDING_ELECTRIFICATION_ERROR);
5053
}
5154

5255
@Override
@@ -90,7 +93,7 @@ public static Pathfinding.Result<SignalingRoute> runPathfinding(
9093
SignalingInfra infra,
9194
PathfindingWaypoint[][] reqWaypoints,
9295
Collection<RollingStock> rollingStocks
93-
) throws NoPathFoundError {
96+
) throws NoPathFoundError {
9497
// parse the waypoints
9598
var waypoints = new ArrayList<Collection<Pathfinding.EdgeLocation<SignalingRoute>>>();
9699
for (var step : reqWaypoints) {
@@ -138,14 +141,14 @@ private static Pathfinding.Result<SignalingRoute> computePaths(
138141
// check there is no path without adding constraints
139142
var possiblePathWithoutErrorNoConstraints =
140143
new Pathfinding<>(new GraphAdapter<>(infra.getSignalingRouteGraph()))
141-
.setEdgeToLength(route -> route.getInfraRoute().getLength())
142-
.setRemainingDistanceEstimator(remainingDistanceEstimator)
143-
.runPathfinding(waypoints);
144+
.setEdgeToLength(route -> route.getInfraRoute().getLength())
145+
.setRemainingDistanceEstimator(remainingDistanceEstimator)
146+
.runPathfinding(waypoints);
144147
if (possiblePathWithoutErrorNoConstraints == null) {
145148
throw new NoPathFoundError(PATH_FINDING_GENERIC_ERROR);
146149
}
147150
// handling errors
148-
for (EdgeToRanges<SignalingRoute> currentConstraint: constraintsList) {
151+
for (EdgeToRanges<SignalingRoute> currentConstraint : constraintsList) {
149152
var possiblePathWithoutError = new Pathfinding<>(new GraphAdapter<>(infra.getSignalingRouteGraph()))
150153
.setEdgeToLength(route -> route.getInfraRoute().getLength())
151154
.addBlockedRangeOnEdges(currentConstraint)

0 commit comments

Comments
 (0)