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")
private static class Context implements QueryTripsContext
{
private boolean canQueryLater = true;
private boolean canQueryEarlier = true;
private Date lastDeparture = null;
private Date firstArrival = null;
public Location from;
@ -92,12 +94,12 @@ public class VrsProvider extends AbstractNetworkProvider
public boolean canQueryLater()
{
return true;
return this.canQueryLater;
}
public boolean canQueryEarlier()
{
return true;
return this.canQueryEarlier;
}
public void departure(Date departure)
@ -125,6 +127,16 @@ public class VrsProvider extends AbstractNetworkProvider
{
return this.firstArrival;
}
public void disableEarlier()
{
this.canQueryEarlier = false;
}
public void disableLater()
{
this.canQueryLater = false;
}
}
private static class LocationWithPosition
@ -948,6 +960,13 @@ public class VrsProvider extends AbstractNetworkProvider
context.to = to;
context.via = via;
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);
}
catch (final JSONException x)