Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #2031 from opentripplanner/leg_switch

Fix LEG_SWITCH bug
  • Loading branch information...
commit 39cf92d8e1656e31bfc3a1ae4fe8377a8fd6a2ee 2 parents 7b30b94 + 54e44dc
@abyrd abyrd authored
View
19 src/main/java/org/opentripplanner/api/resource/GraphPathToTripPlanConverter.java
@@ -132,10 +132,6 @@ private static Itinerary adjustItinerary(RoutingRequest request, Itinerary itine
* @return The generated itinerary
*/
public static Itinerary generateItinerary(GraphPath path, boolean showIntermediateStops, Locale requestedLocale) {
- if (path.states.size() < 2) {
- throw new TrivialPathException();
- }
-
Itinerary itinerary = new Itinerary();
State[] states = new State[path.states.size()];
@@ -223,6 +219,21 @@ private static CoordinateArrayListSequence makeCoordinates(Edge[] edges) {
* @return An array of arrays of states belonging to a single leg (i.e. a two-dimensional array)
*/
private static State[][] sliceStates(State[] states) {
+ boolean trivial = true;
+
+ for (State state : states) {
+ TraverseMode traverseMode = state.getBackMode();
+
+ if (traverseMode != null && traverseMode != TraverseMode.LEG_SWITCH) {
+ trivial = false;
+ break;
+ }
+ }
+
+ if (trivial) {
+ throw new TrivialPathException();
+ }
+
int[] legIndexPairs = {0, states.length - 1};
List<int[]> legsIndexes = new ArrayList<int[]>();
View
41 src/test/java/org/opentripplanner/api/resource/GraphPathToTripPlanConverterTest.java
@@ -74,6 +74,7 @@
import org.opentripplanner.routing.edgetype.TimetableSnapshot;
import org.opentripplanner.routing.edgetype.TransitBoardAlight;
import org.opentripplanner.routing.edgetype.TripPattern;
+import org.opentripplanner.routing.error.TrivialPathException;
import org.opentripplanner.routing.graph.Graph;
import org.opentripplanner.routing.location.StreetLocation;
import org.opentripplanner.routing.services.FareService;
@@ -154,6 +155,46 @@ public void testEndWithLegSwitch() {
}
/**
+ * Test that empty graph paths throw a TrivialPathException
+ */
+ @Test(expected = TrivialPathException.class)
+ public void testEmptyGraphPath() {
+ RoutingRequest options = new RoutingRequest();
+ Graph graph = new Graph();
+ ExitVertex vertex = new ExitVertex(graph, "Vertex", 0, 0);
+
+ options.rctx = new RoutingContext(options, graph, vertex, vertex);
+
+ GraphPath graphPath = new GraphPath(new State(options), false);
+
+ GraphPathToTripPlanConverter.generateItinerary(graphPath, false, locale);
+ }
+
+ /**
+ * Test that graph paths with only null and LEG_SWITCH modes throw a TrivialPathException
+ */
+ @Test(expected = TrivialPathException.class)
+ public void testLegSwitchOnlyGraphPath() {
+ RoutingRequest options = new RoutingRequest();
+ Graph graph = new Graph();
+
+ ExitVertex start = new ExitVertex(graph, "Start", 0, -90);
+ ExitVertex middle = new ExitVertex(graph, "Middle", 0, 0);
+ ExitVertex end = new ExitVertex(graph, "End", 0, 90);
+
+ FreeEdge depart = new FreeEdge(start, middle);
+ LegSwitchingEdge arrive = new LegSwitchingEdge(middle, end);
+
+ options.rctx = new RoutingContext(options, graph, start, end);
+
+ State intermediate = depart.traverse(new State(options));
+
+ GraphPath graphPath = new GraphPath(arrive.traverse(intermediate), false);
+
+ GraphPathToTripPlanConverter.generateItinerary(graphPath, false, locale);
+ }
+
+ /**
* Build three GraphPath objects that can be used for testing for forward, backward and onboard.
* This method doesn't rely on any routing code.
* Leg 0: Walking towards the train station
Please sign in to comment.
Something went wrong with that request. Please try again.