queryNearbyStations() has ResultHeader as well

git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@787 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
andreas.schildbach@gmail.com 2011-09-18 13:25:37 +00:00
parent 2b6090bdea
commit 5cbbd7f175
5 changed files with 26 additions and 23 deletions

View file

@ -188,7 +188,7 @@ public abstract class AbstractEfaProvider implements NetworkProvider
}
}
protected List<Location> xmlCoordRequest(final int lat, final int lon, final int maxDistance, final int maxStations) throws IOException
protected NearbyStationsResult xmlCoordRequest(final int lat, final int lon, final int maxDistance, final int maxStations) throws IOException
{
final StringBuilder uri = new StringBuilder(apiBase);
uri.append("XML_COORD_REQUEST");
@ -206,7 +206,7 @@ public abstract class AbstractEfaProvider implements NetworkProvider
final XmlPullParser pp = parserFactory.newPullParser();
pp.setInput(is, null);
enterItdRequest(pp);
final ResultHeader header = enterItdRequest(pp);
XmlPullUtil.enter(pp, "itdCoordInfoRequest");
@ -215,7 +215,7 @@ public abstract class AbstractEfaProvider implements NetworkProvider
XmlPullUtil.enter(pp, "coordInfoRequest");
XmlPullUtil.exit(pp, "coordInfoRequest");
final List<Location> results = new ArrayList<Location>();
final List<Location> stations = new ArrayList<Location>();
if (XmlPullUtil.test(pp, "coordInfoItemList"))
{
@ -237,13 +237,13 @@ public abstract class AbstractEfaProvider implements NetworkProvider
XmlPullUtil.exit(pp, "coordInfoItem");
results.add(new Location(LocationType.STATION, id, coord.lat, coord.lon, place, name));
stations.add(new Location(LocationType.STATION, id, coord.lat, coord.lon, place, name));
}
XmlPullUtil.exit(pp, "coordInfoItemList");
}
return results;
return new NearbyStationsResult(header, stations);
}
catch (final XmlPullParserException x)
{
@ -438,7 +438,7 @@ public abstract class AbstractEfaProvider implements NetworkProvider
public NearbyStationsResult queryNearbyStations(final Location location, final int maxDistance, final int maxStations) throws IOException
{
if (location.hasLocation())
return new NearbyStationsResult(xmlCoordRequest(location.lat, location.lon, maxDistance, maxStations));
return xmlCoordRequest(location.lat, location.lon, maxDistance, maxStations);
if (location.type != LocationType.STATION)
throw new IllegalArgumentException("cannot handle: " + location.type);
@ -455,7 +455,7 @@ public abstract class AbstractEfaProvider implements NetworkProvider
final XmlPullParser pp = parserFactory.newPullParser();
pp.setInput(is, null);
enterItdRequest(pp);
final ResultHeader header = enterItdRequest(pp);
if (!XmlPullUtil.jumpToStartTag(pp, null, "itdOdv") || !"dm".equals(pp.getAttributeValue(null, "usage")))
throw new IllegalStateException("cannot find <itdOdv usage=\"dm\" />");
@ -518,9 +518,9 @@ public abstract class AbstractEfaProvider implements NetworkProvider
stations.add(ownStation);
if (maxStations == 0 || maxStations >= stations.size())
return new NearbyStationsResult(stations);
return new NearbyStationsResult(header, stations);
else
return new NearbyStationsResult(stations.subList(0, maxStations));
return new NearbyStationsResult(header, stations.subList(0, maxStations));
}
else if ("list".equals(nameState))
{
@ -535,11 +535,11 @@ public abstract class AbstractEfaProvider implements NetworkProvider
stations.add(newLocation);
}
return new NearbyStationsResult(stations);
return new NearbyStationsResult(header, stations);
}
else if ("notidentified".equals(nameState))
{
return new NearbyStationsResult(NearbyStationsResult.Status.INVALID_STATION);
return new NearbyStationsResult(header, NearbyStationsResult.Status.INVALID_STATION);
}
else
{

View file

@ -1177,9 +1177,9 @@ public abstract class AbstractHafasProvider implements NetworkProvider
final String text = mMessage.group(2);
if (code.equals("H730")) // Your input is not valid
return new NearbyStationsResult(NearbyStationsResult.Status.INVALID_STATION);
return new NearbyStationsResult(null, NearbyStationsResult.Status.INVALID_STATION);
if (code.equals("H890")) // No trains in result
return new NearbyStationsResult(stations);
return new NearbyStationsResult(null, stations);
throw new IllegalArgumentException("unknown error " + code + ", " + text);
}
@ -1215,7 +1215,7 @@ public abstract class AbstractHafasProvider implements NetworkProvider
}
}
return new NearbyStationsResult(stations);
return new NearbyStationsResult(null, stations);
}
protected final NearbyStationsResult jsonNearbyStations(final String uri) throws IOException
@ -1251,7 +1251,7 @@ public abstract class AbstractHafasProvider implements NetworkProvider
throw new RuntimeException("cannot parse: '" + page + "' on " + uri, x);
}
return new NearbyStationsResult(stations);
return new NearbyStationsResult(null, stations);
}
private final static Pattern P_NEARBY_COARSE = Pattern.compile("<tr class=\"(zebra[^\"]*)\">(.*?)</tr>", Pattern.DOTALL);
@ -1302,7 +1302,7 @@ public abstract class AbstractHafasProvider implements NetworkProvider
}
}
return new NearbyStationsResult(stations);
return new NearbyStationsResult(null, stations);
}
private static final Pattern P_LINE_SBAHN = Pattern.compile("SN?\\d*");

View file

@ -118,9 +118,9 @@ public final class BahnProvider extends AbstractHafasProvider
}
if (maxStations == 0 || maxStations >= stations.size())
return new NearbyStationsResult(stations);
return new NearbyStationsResult(null, stations);
else
return new NearbyStationsResult(stations.subList(0, maxStations));
return new NearbyStationsResult(null, stations.subList(0, maxStations));
}
else
{

View file

@ -133,7 +133,7 @@ public final class BvgProvider extends AbstractHafasProvider
if (mError.find())
{
if (mError.group(1) != null)
return new NearbyStationsResult(NearbyStationsResult.Status.INVALID_STATION);
return new NearbyStationsResult(null, NearbyStationsResult.Status.INVALID_STATION);
}
final List<Location> stations = new ArrayList<Location>();
@ -172,9 +172,9 @@ public final class BvgProvider extends AbstractHafasProvider
}
if (maxStations == 0 || maxStations >= stations.size())
return new NearbyStationsResult(stations);
return new NearbyStationsResult(null, stations);
else
return new NearbyStationsResult(stations.subList(0, maxStations));
return new NearbyStationsResult(null, stations.subList(0, maxStations));
}
else
{

View file

@ -29,17 +29,20 @@ public final class NearbyStationsResult
OK, INVALID_STATION, SERVICE_DOWN
}
public final ResultHeader header;
public final Status status;
public final List<Location> stations;
public NearbyStationsResult(final List<Location> stations)
public NearbyStationsResult(final ResultHeader header, final List<Location> stations)
{
this.header = header;
this.status = Status.OK;
this.stations = stations;
}
public NearbyStationsResult(final Status status)
public NearbyStationsResult(final ResultHeader header, final Status status)
{
this.header = header;
this.status = status;
this.stations = null;
}