@@ -208,6 +208,7 @@ public <T extends Vertex> List<T> getVerticesOfType(Class<T> cls) {
208
208
*/
209
209
@ Nullable
210
210
public TransitStopVertex getStopVertexForStopId (FeedScopedId id ) {
211
+ requireIndex ();
211
212
return streetIndex .findTransitStopVertex (id );
212
213
}
213
214
@@ -253,6 +254,9 @@ public boolean containsVertex(Vertex v) {
253
254
254
255
public void remove (Vertex vertex ) {
255
256
vertices .remove (vertex .getLabel ());
257
+ if (streetIndex != null ) {
258
+ streetIndex .remove (vertex );
259
+ }
256
260
}
257
261
258
262
public void removeIfUnconnected (Vertex v ) {
@@ -282,7 +286,7 @@ public int countEdges() {
282
286
/**
283
287
* Perform indexing on vertices, edges and create transient data structures. This used to be done
284
288
* in readObject methods upon deserialization, but stand-alone mode now allows passing graphs from
285
- * graphbuilder to server in memory, without a round trip through serialization.
289
+ * graph builder to server in memory, without a round trip through serialization.
286
290
* <p>
287
291
* TODO OTP2 - Indexing the streetIndex is not something that should be delegated outside the
288
292
* - graph. This allows a module to index the streetIndex BEFORE another module add
@@ -294,6 +298,15 @@ public void index() {
294
298
LOG .info ("Index street model complete." );
295
299
}
296
300
301
+ /**
302
+ * Index this graph if it hasn't been already.
303
+ */
304
+ public void requestIndex () {
305
+ if (streetIndex == null ) {
306
+ index ();
307
+ }
308
+ }
309
+
297
310
@ Nullable
298
311
public OpeningHoursCalendarService getOpeningHoursCalendarService () {
299
312
return this .openingHoursCalendarService ;
@@ -314,6 +327,7 @@ public Collection<Vertex> findVertices(Envelope env) {
314
327
* the station centroid if the station is configured to route to centroid.
315
328
*/
316
329
public Set <Vertex > findStopVertices (FeedScopedId stopId ) {
330
+ requireIndex ();
317
331
return streetIndex .findStopVertices (stopId );
318
332
}
319
333
@@ -374,12 +388,6 @@ public void setDistanceBetweenElevationSamples(double distanceBetweenElevationSa
374
388
CompactElevationProfile .setDistanceBetweenSamplesM (distanceBetweenElevationSamples );
375
389
}
376
390
377
- private void indexIfNotIndexed () {
378
- if (streetIndex == null ) {
379
- index ();
380
- }
381
- }
382
-
383
391
private void requireIndex () {
384
392
if (streetIndex == null ) {
385
393
throw new IllegalStateException ("Graph must be indexed before querying." );
0 commit comments