mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-18 08:19:51 +00:00
nearbyStations() gets its own result object
git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@237 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
parent
ae3cc77277
commit
94d99f7e53
18 changed files with 115 additions and 70 deletions
|
@ -17,6 +17,7 @@
|
|||
|
||||
package de.schildbach.pte;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.util.ArrayList;
|
||||
|
@ -34,9 +35,9 @@ import org.xmlpull.v1.XmlPullParserFactory;
|
|||
|
||||
import de.schildbach.pte.dto.Autocomplete;
|
||||
import de.schildbach.pte.dto.Departure;
|
||||
import de.schildbach.pte.dto.NearbyStationsResult;
|
||||
import de.schildbach.pte.dto.QueryDeparturesResult;
|
||||
import de.schildbach.pte.dto.Station;
|
||||
import de.schildbach.pte.dto.QueryDeparturesResult.Status;
|
||||
import de.schildbach.pte.util.Color;
|
||||
import de.schildbach.pte.util.ParserUtils;
|
||||
import de.schildbach.pte.util.XmlPullUtil;
|
||||
|
@ -88,7 +89,7 @@ public abstract class AbstractEfaProvider implements NetworkProvider
|
|||
|
||||
protected abstract String nearbyStationUri(String stationId);
|
||||
|
||||
public List<Station> nearbyStations(final String stationId, final int lat, final int lon, final int maxDistance, final int maxStations)
|
||||
public NearbyStationsResult nearbyStations(final String stationId, final int lat, final int lon, final int maxDistance, final int maxStations)
|
||||
throws IOException
|
||||
{
|
||||
String uri = null;
|
||||
|
@ -104,7 +105,7 @@ public abstract class AbstractEfaProvider implements NetworkProvider
|
|||
final CharSequence page = ParserUtils.scrape(uri);
|
||||
|
||||
if (P_NEARBY_MESSAGES.matcher(page).find())
|
||||
return null;
|
||||
return new NearbyStationsResult(uri, NearbyStationsResult.Status.SERVICE_DOWN);
|
||||
|
||||
final XmlPullParserFactory factory = XmlPullParserFactory.newInstance(System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null);
|
||||
final XmlPullParser pp = factory.newPullParser();
|
||||
|
@ -157,13 +158,13 @@ public abstract class AbstractEfaProvider implements NetworkProvider
|
|||
}
|
||||
|
||||
if (maxStations == 0 || maxStations >= stations.size())
|
||||
return stations;
|
||||
return new NearbyStationsResult(uri, stations);
|
||||
else
|
||||
return stations.subList(0, maxStations);
|
||||
return new NearbyStationsResult(uri, stations.subList(0, maxStations));
|
||||
}
|
||||
else if (nameState.equals("notidentified"))
|
||||
{
|
||||
return null;
|
||||
return new NearbyStationsResult(uri, NearbyStationsResult.Status.INVALID_STATION);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -174,6 +175,10 @@ public abstract class AbstractEfaProvider implements NetworkProvider
|
|||
{
|
||||
throw new RuntimeException(x);
|
||||
}
|
||||
catch (final FileNotFoundException x)
|
||||
{
|
||||
return new NearbyStationsResult(uri, NearbyStationsResult.Status.SERVICE_DOWN);
|
||||
}
|
||||
}
|
||||
|
||||
private static final Pattern P_LINE_IRE = Pattern.compile("IRE\\d+");
|
||||
|
@ -497,7 +502,7 @@ public abstract class AbstractEfaProvider implements NetworkProvider
|
|||
}
|
||||
else if (nameState.equals("notidentified"))
|
||||
{
|
||||
return new QueryDeparturesResult(uri, Status.INVALID_STATION);
|
||||
return new QueryDeparturesResult(uri, QueryDeparturesResult.Status.INVALID_STATION);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue