VRS: Avoid endless queryMoreTrips() loop by not allowing earlier or later trips if current arrival or departure query found only one trip.

This commit is contained in:
Michael Dyrna 2015-03-25 23:01:02 +01:00 committed by Andreas Schildbach
parent 154085da1d
commit bc9679310a

View file

@ -79,6 +79,8 @@ public class VrsProvider extends AbstractNetworkProvider
@SuppressWarnings("serial") @SuppressWarnings("serial")
private static class Context implements QueryTripsContext private static class Context implements QueryTripsContext
{ {
private boolean canQueryLater = true;
private boolean canQueryEarlier = true;
private Date lastDeparture = null; private Date lastDeparture = null;
private Date firstArrival = null; private Date firstArrival = null;
public Location from; public Location from;
@ -92,12 +94,12 @@ public class VrsProvider extends AbstractNetworkProvider
public boolean canQueryLater() public boolean canQueryLater()
{ {
return true; return this.canQueryLater;
} }
public boolean canQueryEarlier() public boolean canQueryEarlier()
{ {
return true; return this.canQueryEarlier;
} }
public void departure(Date departure) public void departure(Date departure)
@ -125,6 +127,16 @@ public class VrsProvider extends AbstractNetworkProvider
{ {
return this.firstArrival; return this.firstArrival;
} }
public void disableEarlier()
{
this.canQueryEarlier = false;
}
public void disableLater()
{
this.canQueryLater = false;
}
} }
private static class LocationWithPosition private static class LocationWithPosition
@ -948,6 +960,13 @@ public class VrsProvider extends AbstractNetworkProvider
context.to = to; context.to = to;
context.via = via; context.via = via;
context.products = products; context.products = products;
if (trips.size() == 1)
{
if (dep)
context.disableLater();
else
context.disableEarlier();
}
return new QueryTripsResult(header, uri.toString(), from, via, to, context, trips); return new QueryTripsResult(header, uri.toString(), from, via, to, context, trips);
} }
catch (final JSONException x) catch (final JSONException x)