use connection query location ID syntax for Berlin as well

git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@705 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
andreas.schildbach@gmail.com 2011-06-18 12:32:20 +00:00
parent c99e99b0f7
commit f442cd5ead
2 changed files with 42 additions and 53 deletions

View file

@ -28,6 +28,7 @@ import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
import java.util.regex.Matcher;
@ -1076,34 +1077,54 @@ public abstract class AbstractHafasProvider implements NetworkProvider
throw new IllegalArgumentException("cannot handle: " + location.toDebugString());
}
protected static final String locationId(final Location location)
protected final String locationId(final Location location)
{
final StringBuilder builder = new StringBuilder();
builder.append("A=").append(locationType(location));
if (location.hasLocation())
builder.append("@X=" + location.lon + "@Y=" + location.lat);
if (location.name != null)
builder.append("@G=" + location.name);
if (location.type == LocationType.STATION && location.hasId())
builder.append("@L=").append(location.id);
return builder.toString();
final StringBuilder id = new StringBuilder();
id.append("A=").append(locationType(location));
if (location.type == LocationType.STATION && location.hasId() && isValidStationId(location.id))
{
id.append("@L=").append(location.id);
}
else if (location.hasLocation())
{
id.append("@X=").append(location.lon);
id.append("@Y=").append(location.lat);
id.append("@O=").append(
location.name != null ? location.name : String.format(Locale.ENGLISH, "%.6f, %.6f", location.lat / 1E6, location.lon / 1E6));
}
else if (location.name != null)
{
id.append("@G=").append(location.name);
if (location.type != LocationType.ANY)
id.append('!');
}
return id.toString();
}
protected static final int locationType(final Location location)
{
if (location.type == LocationType.STATION)
final LocationType type = location.type;
if (type == LocationType.STATION)
return 1;
if (location.type == LocationType.POI)
if (type == LocationType.POI)
return 4;
if (location.type == LocationType.ADDRESS && location.hasLocation())
if (type == LocationType.ADDRESS && location.hasLocation())
return 16;
if (location.type == LocationType.ADDRESS && location.name != null)
if (type == LocationType.ADDRESS && location.name != null)
return 2;
if (location.type == LocationType.ANY)
if (type == LocationType.ANY)
return 255;
throw new IllegalArgumentException(location.type.toString());
}
protected boolean isValidStationId(int id)
{
return true;
}
public GetConnectionDetailsResult getConnectionDetails(String connectionUri) throws IOException
{
throw new UnsupportedOperationException();

View file

@ -430,10 +430,10 @@ public final class BvgProvider extends AbstractHafasProvider
uri.append("?start=Suchen");
appendLocationBvg(uri, from, "S0");
appendLocationBvg(uri, to, "Z0");
uri.append("&REQ0JourneyStopsS0ID=").append(ParserUtils.urlEncode(locationId(from)));
uri.append("&REQ0JourneyStopsZ0ID=").append(ParserUtils.urlEncode(locationId(to)));
if (via != null)
appendLocationBvg(uri, via, "1.0");
uri.append("&REQ0JourneyStops1.0ID=").append(ParserUtils.urlEncode(locationId(via)));
uri.append("&REQ0HafasSearchForw=").append(dep ? "1" : "0");
uri.append("&REQ0JourneyDate=").append(
@ -498,42 +498,10 @@ public final class BvgProvider extends AbstractHafasProvider
return uri.toString();
}
private static final void appendLocationBvg(final StringBuilder uri, final Location location, final String paramSuffix)
@Override
protected boolean isValidStationId(int id)
{
uri.append("&REQ0JourneyStops").append(paramSuffix).append("A=").append(locationTypeValue(location));
if (location.type == LocationType.STATION && location.hasId() && location.id >= 1000000)
uri.append("&REQ0JourneyStops").append(paramSuffix).append("L=").append(location.id);
if (location.hasLocation())
{
uri.append("&REQ0JourneyStops").append(paramSuffix).append("X=").append(location.lon);
uri.append("&REQ0JourneyStops").append(paramSuffix).append("Y=").append(location.lat);
if (location.name == null)
uri.append("&REQ0JourneyStops").append(paramSuffix).append("O=")
.append(ParserUtils.urlEncode(String.format(Locale.ENGLISH, "%.6f, %.6f", location.lat / 1E6, location.lon / 1E6)));
}
if (location.name != null)
{
uri.append("&REQ0JourneyStops").append(paramSuffix).append("G=").append(ParserUtils.urlEncode(location.name));
if (location.type != LocationType.ANY)
uri.append('!');
}
}
private static final int locationTypeValue(final Location location)
{
final LocationType type = location.type;
if (type == LocationType.STATION)
return 1;
if (type == LocationType.ADDRESS)
return 2;
if (type == LocationType.POI)
return 4;
if (type == LocationType.ANY)
return 255;
throw new IllegalArgumentException(type.toString());
return id >= 1000000;
}
private static final Pattern P_PRE_ADDRESS = Pattern.compile(