org.opentripplanner.graph_builder.linking.DisposableEdgeCollection Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of otp Show documentation
Show all versions of otp Show documentation
The OpenTripPlanner multimodal journey planning system
package org.opentripplanner.graph_builder.linking;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import org.opentripplanner.routing.graph.Edge;
import org.opentripplanner.routing.graph.Graph;
import org.opentripplanner.routing.graph.Vertex;
/**
* This class is used to keep track of temporary edges added to the graph, so that they can be
* removed from the graph when no longer needed.
*/
public class DisposableEdgeCollection {
private final Graph graph;
private final Scope scope;
private final Set edges = new HashSet<>();
public DisposableEdgeCollection(Graph graph) {
this(graph, null);
}
public DisposableEdgeCollection(Graph graph, Scope scope) {
this.graph = graph;
this.scope = scope;
}
public void addEdge(Edge edge) {
this.edges.add(edge);
}
/**
* Removes all the edges in this collection from the graph.
*/
public void disposeEdges() {
if (scope == Scope.REALTIME) {
for (Edge e : edges) {
graph.getLinker().removeEdgeFromIndex(e, scope);
}
}
Collection vertices = new ArrayList<>();
for (Edge e : edges) {
vertices.add(e.getFromVertex());
vertices.add(e.getToVertex());
graph.removeEdge(e);
}
for (Vertex v : vertices) {
graph.removeIfUnconnected(v);
}
edges.clear();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy