Skip to content

Commit b951c49

Browse files
committed
refactor: clean up committedNetworks API and document geofencing state
Rename commitToNetwork to bindToNetwork to avoid confusion with the committedNetworks set. Remove test-only setCommittedNetworks method. Add javadoc to geofencing state fields in StateData and their public getters on State.
1 parent d7aadb4 commit b951c49

7 files changed

Lines changed: 37 additions & 34 deletions

File tree

street/src/main/java/org/opentripplanner/street/model/edge/StreetEdge.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,10 +1267,10 @@ private State[] performGenericBoundaryFork(State s0, State genericState) {
12671267
if (!isNetworkAllowedByRequest(network, request)) {
12681268
continue;
12691269
}
1270-
var committed = doTraverse(s0, s0.currentMode(), false);
1271-
if (committed != null) {
1272-
committed.commitToNetwork(network);
1273-
State commitState = committed.makeState();
1270+
var networkBranch = doTraverse(s0, s0.currentMode(), false);
1271+
if (networkBranch != null) {
1272+
networkBranch.bindToNetwork(network);
1273+
State commitState = networkBranch.makeState();
12741274
if (commitState != null) {
12751275
states.add(commitState);
12761276
}

street/src/main/java/org/opentripplanner/street/search/state/State.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,10 +485,16 @@ public <T extends ExtensionRequestContext> Optional<T> getExtensionRequestContex
485485
return Optional.empty();
486486
}
487487

488+
/**
489+
* The geofencing zones that currently contain this state's position.
490+
*/
488491
public Set<GeofencingZone> getCurrentGeofencingZones() {
489492
return stateData.currentGeofencingZones;
490493
}
491494

495+
/**
496+
* Networks for which this generic state has already forked committed branches at zone boundaries.
497+
*/
492498
public Set<String> getCommittedNetworks() {
493499
return stateData.committedNetworks;
494500
}

street/src/main/java/org/opentripplanner/street/search/state/StateData.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,19 @@ public class StateData implements Cloneable {
5555
/** This boolean is set to true upon transition from a normal street to a no-through-traffic street. */
5656
protected boolean enteredNoThroughTrafficArea;
5757

58+
/**
59+
* The geofencing zones that currently contain this state's position. Updated at boundary
60+
* crossings by {@link StateEditor#updateGeofencingZones}. Used to enforce per-field restrictions
61+
* (no-traversal, no-drop-off) resolved via priority-based precedence.
62+
*/
5863
protected Set<GeofencingZone> currentGeofencingZones = Set.of();
64+
65+
/**
66+
* Networks for which this generic (null-network) RENTING_FLOATING state has already forked
67+
* committed branches at zone boundaries. Prevents duplicate forking at subsequent boundary
68+
* crossings for the same network. Participates in dominance: a state whose committedNetworks
69+
* is a superset dominates one with a subset (it has already explored more network options).
70+
*/
5971
protected Set<String> committedNetworks = Set.of();
6072

6173
/** Private constructor, use static methods to get a set of initial states. */

street/src/main/java/org/opentripplanner/street/search/state/StateEditor.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -459,22 +459,20 @@ public void initializeGeofencingZones(Set<GeofencingZone> zones) {
459459
stateData.currentGeofencingZones = Set.copyOf(zones);
460460
}
461461

462-
public void setCommittedNetworks(Set<String> networks) {
463-
if (networks.equals(stateData.committedNetworks)) {
464-
return;
465-
}
466-
cloneStateDataAsNeeded();
467-
stateData.committedNetworks = Set.copyOf(networks);
468-
}
469-
470462
/**
471-
* Commit a generic RENTING_FLOATING state to a specific network at a boundary fork.
463+
* Bind this state to a specific vehicle rental network. Transitions a generic (null-network)
464+
* RENTING_FLOATING state into a network-specific state. Called on the forked branch in
465+
* {@code performGenericBoundaryFork}.
472466
*/
473-
public void commitToNetwork(String network) {
467+
public void bindToNetwork(String network) {
474468
cloneStateDataAsNeeded();
475469
stateData.vehicleRentalNetwork = network;
476470
}
477471

472+
/**
473+
* Record that this generic state has already forked a committed branch for the given network.
474+
* Prevents duplicate forking at subsequent boundary crossings for the same network.
475+
*/
478476
public void addCommittedNetwork(String network) {
479477
if (stateData.committedNetworks.contains(network)) {
480478
return;

street/src/test/java/org/opentripplanner/street/model/edge/StreetEdgeGeofencingTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,9 @@ private State initialStateWithCommittedNetworks(
794794
null,
795795
false
796796
);
797-
editor.setCommittedNetworks(committedNetworks);
797+
for (var network : committedNetworks) {
798+
editor.addCommittedNetwork(network);
799+
}
798800
return editor.makeState();
799801
}
800802
}

street/src/test/java/org/opentripplanner/street/model/edge/VehicleRentalEdgeTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ void committedNetworkBlocksGenericPickup() {
408408
var arriveByReq = StreetSearchRequest.copyOf(request).withArriveBy(true).build();
409409
var editor = new org.opentripplanner.street.search.state.StateEditor(vertex, arriveByReq);
410410
editor.dropFloatingVehicle(SCOOTER, ELECTRIC, null, true);
411-
editor.setCommittedNetworks(Set.of(vertex.getStation().network()));
411+
editor.addCommittedNetwork(vertex.getStation().network());
412412
var genericState = editor.makeState();
413413

414414
// The generic state has the station's network in committedNetworks
@@ -431,7 +431,7 @@ void uncommittedNetworkAllowsGenericPickup() {
431431
var arriveByReq = StreetSearchRequest.copyOf(request).withArriveBy(true).build();
432432
var editor = new org.opentripplanner.street.search.state.StateEditor(vertex, arriveByReq);
433433
editor.dropFloatingVehicle(SCOOTER, ELECTRIC, null, true);
434-
editor.setCommittedNetworks(Set.of("some-other-network"));
434+
editor.addCommittedNetwork("some-other-network");
435435
var genericState = editor.makeState();
436436

437437
assertFalse(genericState.getCommittedNetworks().contains(vertex.getStation().network()));

street/src/test/java/org/opentripplanner/street/search/state/StateEditorGeofencingZoneTest.java

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -172,21 +172,6 @@ void updateGeofencingZonesArriveByFlipsDirection() {
172172
assertFalse(s2.getCurrentGeofencingZones().contains(ZONE));
173173
}
174174

175-
@Test
176-
void setCommittedNetworks() {
177-
var req = StreetSearchRequest.of().withMode(StreetMode.SCOOTER_RENTAL).build();
178-
var v = intersectionVertex(1, 1);
179-
var v2 = intersectionVertex(2, 2);
180-
var edge = streetEdge(v, v2);
181-
var s0 = new State(v, req);
182-
var editor = s0.edit(edge);
183-
184-
editor.setCommittedNetworks(Set.of("tier", "bird"));
185-
186-
var s1 = editor.makeState();
187-
assertEquals(Set.of("tier", "bird"), s1.getCommittedNetworks());
188-
}
189-
190175
@Test
191176
void addCommittedNetwork() {
192177
var req = StreetSearchRequest.of().withMode(StreetMode.SCOOTER_RENTAL).build();
@@ -197,7 +182,7 @@ void addCommittedNetwork() {
197182
var edge2 = streetEdge(v2, v3);
198183
var s0 = new State(v, req);
199184
var editor = s0.edit(edge);
200-
editor.setCommittedNetworks(Set.of("tier"));
185+
editor.addCommittedNetwork("tier");
201186
var s1 = editor.makeState();
202187

203188
var editor2 = s1.edit(edge2);
@@ -217,7 +202,7 @@ void addCommittedNetworkNoOpIfAlreadyPresent() {
217202
var edge2 = streetEdge(v2, v3);
218203
var s0 = new State(v, req);
219204
var editor = s0.edit(edge);
220-
editor.setCommittedNetworks(Set.of("tier"));
205+
editor.addCommittedNetwork("tier");
221206
var s1 = editor.makeState();
222207

223208
var editor2 = s1.edit(edge2);

0 commit comments

Comments
 (0)