place in connections

git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@446 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
andreas.schildbach@gmail.com 2011-01-11 17:20:23 +00:00
parent 0d0d51725a
commit 612111edef
8 changed files with 87 additions and 53 deletions

View file

@ -88,8 +88,9 @@ public abstract class AbstractEfaProvider implements NetworkProvider
if (!XmlPullUtil.jumpToStartTag(pp, null, "itdOdv") || !"origin".equals(pp.getAttributeValue(null, "usage")))
throw new IllegalStateException("cannot find <itdOdv usage=\"origin\" />");
XmlPullUtil.enter(pp, "itdOdv");
XmlPullUtil.enter(pp, "itdOdvPlace");
XmlPullUtil.exit(pp, "itdOdvPlace");
final String place = processItdOdvPlace(pp);
if (!XmlPullUtil.test(pp, "itdOdvName"))
throw new IllegalStateException("cannot find <itdOdvName />");
final String nameState = XmlPullUtil.attr(pp, "state");
@ -99,7 +100,7 @@ public abstract class AbstractEfaProvider implements NetworkProvider
if ("identified".equals(nameState) || "list".equals(nameState))
while (XmlPullUtil.test(pp, "odvNameElem"))
results.add(processOdvNameElem(pp));
results.add(processOdvNameElem(pp, place));
// parse assigned stops
if (XmlPullUtil.jumpToStartTag(pp, null, "itdOdvAssignedStops"))
@ -127,7 +128,30 @@ public abstract class AbstractEfaProvider implements NetworkProvider
}
}
private Location processOdvNameElem(final XmlPullParser pp) throws XmlPullParserException, IOException
private String processItdOdvPlace(final XmlPullParser pp) throws XmlPullParserException, IOException
{
if (!XmlPullUtil.test(pp, "itdOdvPlace"))
throw new IllegalStateException("expecting <itdOdvPlace />");
final String placeState = XmlPullUtil.attr(pp, "state");
XmlPullUtil.enter(pp, "itdOdvPlace");
String place = null;
if ("identified".equals(placeState))
{
if (XmlPullUtil.test(pp, "odvPlaceElem"))
{
XmlPullUtil.enter(pp, "odvPlaceElem");
place = normalizeLocationName(pp.getText());
XmlPullUtil.exit(pp, "odvPlaceElem");
}
}
XmlPullUtil.exit(pp, "itdOdvPlace");
return place;
}
private Location processOdvNameElem(final XmlPullParser pp, final String defaultPlace) throws XmlPullParserException, IOException
{
if (!XmlPullUtil.test(pp, "odvNameElem"))
throw new IllegalStateException("expecting <odvNameElem />");
@ -137,6 +161,8 @@ public abstract class AbstractEfaProvider implements NetworkProvider
final String stopIdStr = pp.getAttributeValue(null, "stopID");
final String poiIdStr = pp.getAttributeValue(null, "poiID");
final String streetIdStr = pp.getAttributeValue(null, "streetID");
final String place = !"loc".equals(anyType) ? normalizeLocationName(pp.getAttributeValue(null, "locality")) : null;
final String name = normalizeLocationName(pp.getAttributeValue(null, "objectName"));
int lat = 0, lon = 0;
if ("WGS84".equals(pp.getAttributeValue(null, "mapName")))
{
@ -193,10 +219,10 @@ public abstract class AbstractEfaProvider implements NetworkProvider
}
XmlPullUtil.enter(pp, "odvNameElem");
final String name = normalizeLocationName(pp.getText());
final String longName = normalizeLocationName(pp.getText());
XmlPullUtil.exit(pp, "odvNameElem");
return new Location(type, id, lat, lon, name);
return new Location(type, id, lat, lon, place != null ? place : defaultPlace, name != null ? name : longName);
}
private Location processItdOdvAssignedStop(final XmlPullParser pp)
@ -209,7 +235,7 @@ public abstract class AbstractEfaProvider implements NetworkProvider
lon = Integer.parseInt(pp.getAttributeValue(null, "x"));
}
final String name = normalizeLocationName(pp.getAttributeValue(null, "nameWithPlace"));
return new Location(LocationType.STATION, id, lat, lon, name);
return new Location(LocationType.STATION, id, lat, lon, null, name);
}
protected abstract String nearbyLatLonUri(int lat, int lon);
@ -242,17 +268,7 @@ public abstract class AbstractEfaProvider implements NetworkProvider
throw new IllegalStateException("cannot find <itdOdv usage=\"dm\" />");
XmlPullUtil.enter(pp, "itdOdv");
String place = null;
XmlPullUtil.require(pp, "itdOdvPlace");
final String placeState = pp.getAttributeValue(null, "state");
XmlPullUtil.enter(pp, "itdOdvPlace");
if ("identified".equals(placeState))
{
XmlPullUtil.enter(pp, "odvPlaceElem");
place = normalizeLocationName(pp.getText());
XmlPullUtil.exit(pp, "odvPlaceElem");
}
XmlPullUtil.exit(pp, "itdOdvPlace");
final String place = processItdOdvPlace(pp);
XmlPullUtil.require(pp, "itdOdvName");
final String nameState = pp.getAttributeValue(null, "state");
@ -310,10 +326,17 @@ public abstract class AbstractEfaProvider implements NetworkProvider
stations.add(newStation);
}
else
{
if (!pp.isEmptyElementTag())
{
XmlPullUtil.enter(pp, "itdOdvAssignedStop");
XmlPullUtil.exit(pp, "itdOdvAssignedStop");
}
else
{
XmlPullUtil.next(pp);
}
}
}
}
@ -333,7 +356,7 @@ public abstract class AbstractEfaProvider implements NetworkProvider
XmlPullUtil.next(pp);
while (XmlPullUtil.test(pp, "odvNameElem"))
{
final Location location = processOdvNameElem(pp);
final Location location = processOdvNameElem(pp, place);
if (location.type == LocationType.STATION)
{
final Station newStation = new Station(location.id, null, location.name, null, location.lat, location.lon, 0, null, null);
@ -391,6 +414,8 @@ public abstract class AbstractEfaProvider implements NetworkProvider
return 'T' + str;
if (noTrainName.equals("Badner Bahn"))
return 'T' + str;
if (noTrainName.equals("Stadtbus"))
return 'B' + str;
if (noTrainName.equals("Citybus"))
return 'B' + str;
if (noTrainName.equals("Regionalbus"))
@ -967,6 +992,9 @@ public abstract class AbstractEfaProvider implements NetworkProvider
protected static String normalizeLocationName(final String name)
{
if (name == null || name.length() == 0)
return null;
return P_STATION_NAME_WHITESPACE.matcher(name).replaceAll(" ");
}
@ -1043,51 +1071,52 @@ public abstract class AbstractEfaProvider implements NetworkProvider
{
final String usage = XmlPullUtil.attr(pp, "usage");
XmlPullUtil.enter(pp, "itdOdv");
XmlPullUtil.enter(pp, "itdOdvPlace");
XmlPullUtil.exit(pp, "itdOdvPlace");
final String place = processItdOdvPlace(pp);
if (!XmlPullUtil.test(pp, "itdOdvName"))
throw new IllegalStateException("cannot find <itdOdvName /> inside " + usage);
final String state = XmlPullUtil.attr(pp, "state");
final String nameState = XmlPullUtil.attr(pp, "state");
XmlPullUtil.enter(pp, "itdOdvName");
if (XmlPullUtil.test(pp, "itdMessage"))
XmlPullUtil.next(pp);
if ("list".equals(state))
if ("list".equals(nameState))
{
if ("origin".equals(usage))
{
ambiguousFrom = new ArrayList<Location>();
while (XmlPullUtil.test(pp, "odvNameElem"))
ambiguousFrom.add(processOdvNameElem(pp));
ambiguousFrom.add(processOdvNameElem(pp, place));
}
else if ("via".equals(usage))
{
ambiguousVia = new ArrayList<Location>();
while (XmlPullUtil.test(pp, "odvNameElem"))
ambiguousVia.add(processOdvNameElem(pp));
ambiguousVia.add(processOdvNameElem(pp, place));
}
else if ("destination".equals(usage))
{
ambiguousTo = new ArrayList<Location>();
while (XmlPullUtil.test(pp, "odvNameElem"))
ambiguousTo.add(processOdvNameElem(pp));
ambiguousTo.add(processOdvNameElem(pp, place));
}
else
{
throw new IllegalStateException("unknown usage: " + usage);
}
}
else if ("identified".equals(state))
else if ("identified".equals(nameState))
{
if (!XmlPullUtil.test(pp, "odvNameElem"))
throw new IllegalStateException("cannot find <odvNameElem /> inside " + usage);
if ("origin".equals(usage))
from = processOdvNameElem(pp);
from = processOdvNameElem(pp, place);
else if ("via".equals(usage))
via = processOdvNameElem(pp);
via = processOdvNameElem(pp, place);
else if ("destination".equals(usage))
to = processOdvNameElem(pp);
to = processOdvNameElem(pp, place);
else
throw new IllegalStateException("unknown usage: " + usage);
}

View file

@ -81,7 +81,7 @@ public abstract class AbstractHafasProvider implements NetworkProvider
final int id = Integer.parseInt(pp.getAttributeValue(null, "externalStationNr"));
final int x = Integer.parseInt(pp.getAttributeValue(null, "x"));
final int y = Integer.parseInt(pp.getAttributeValue(null, "y"));
return new Location(LocationType.STATION, id, y, x, name);
return new Location(LocationType.STATION, id, y, x, null, name);
}
throw new IllegalStateException("cannot handle: " + type);
}
@ -96,7 +96,7 @@ public abstract class AbstractHafasProvider implements NetworkProvider
name = null;
final int x = Integer.parseInt(pp.getAttributeValue(null, "x"));
final int y = Integer.parseInt(pp.getAttributeValue(null, "y"));
return new Location(LocationType.POI, 0, y, x, name);
return new Location(LocationType.POI, 0, y, x, null, name);
}
throw new IllegalStateException("cannot handle: " + type);
}
@ -111,7 +111,7 @@ public abstract class AbstractHafasProvider implements NetworkProvider
name = null;
final int x = Integer.parseInt(pp.getAttributeValue(null, "x"));
final int y = Integer.parseInt(pp.getAttributeValue(null, "y"));
return new Location(LocationType.ADDRESS, 0, y, x, name);
return new Location(LocationType.ADDRESS, 0, y, x, null, name);
}
throw new IllegalStateException("cannot handle: " + type);
}

View file

@ -110,15 +110,15 @@ public class OebbProvider extends AbstractHafasProvider
if (type == 1) // station
{
results.add(new Location(LocationType.STATION, localId, lat, lon, value));
results.add(new Location(LocationType.STATION, localId, lat, lon, null, value));
}
else if (type == 2) // address
{
results.add(new Location(LocationType.ADDRESS, 0, lat, lon, value));
results.add(new Location(LocationType.ADDRESS, 0, lat, lon, null, value));
}
else if (type == 4) // poi
{
results.add(new Location(LocationType.POI, localId, lat, lon, value));
results.add(new Location(LocationType.POI, localId, lat, lon, null, value));
}
else
{

View file

@ -27,14 +27,16 @@ public final class Location implements Serializable
public final LocationType type;
public final int id;
public final int lat, lon;
public final String place;
public final String name;
public Location(final LocationType type, final int id, final int lat, final int lon, final String name)
public Location(final LocationType type, final int id, final int lat, final int lon, final String place, final String name)
{
this.type = type;
this.id = id;
this.lat = lat;
this.lon = lon;
this.place = place;
this.name = name;
}
@ -44,6 +46,7 @@ public final class Location implements Serializable
this.id = id;
this.lat = 0;
this.lon = 0;
this.place = null;
this.name = name;
}
@ -55,7 +58,7 @@ public final class Location implements Serializable
public String toDebugString()
{
return "[" + type + " " + id + " " + lat + "/" + lon + " '" + name + "']";
return "[" + type + " " + id + " " + lat + "/" + lon + " " + (place != null ? "'" + place + "'" : "null") + " '" + name + "']";
}
@Override

View file

@ -96,16 +96,17 @@ public class GvhProviderLiveTest
@Test
public void shortConnection() throws Exception
{
final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.STATION, 25000031, 0, 0, "Hannover Hauptbahnhof"),
null, new Location(LocationType.STATION, 25001141, "Hannover Bismarckstraße"), new Date(), true, ALL_PRODUCTS, WalkSpeed.FAST);
final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.STATION, 25000031, 0, 0, null,
"Hannover Hauptbahnhof"), null, new Location(LocationType.STATION, 25001141, "Hannover Bismarckstraße"), new Date(), true,
ALL_PRODUCTS, WalkSpeed.FAST);
System.out.println(result);
}
@Test
public void connectionBetweenAnyAndAddress() throws Exception
{
final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.ANY, 0, 53069619, 8799202,
"bremen, neustadtswall 12"), null, new Location(LocationType.ADDRESS, 0, 53104124, 8788575, "Bremen Glücksburger Straße 37"),
final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.ANY, 0, 53069619, 8799202, null,
"bremen, neustadtswall 12"), null, new Location(LocationType.ADDRESS, 0, 53104124, 8788575, null, "Bremen Glücksburger Straße 37"),
new Date(), true, ALL_PRODUCTS, WalkSpeed.NORMAL);
System.out.println(result);
final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.context);
@ -115,8 +116,8 @@ public class GvhProviderLiveTest
@Test
public void connectionBetweenAddresses() throws Exception
{
final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.ADDRESS, 0, 53622859, 10133545,
"Zamenhofweg 14, 22159 Hamburg, Deutschland"), null, new Location(LocationType.ADDRESS, 0, 53734260, 9674990,
final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.ADDRESS, 0, 53622859, 10133545, null,
"Zamenhofweg 14, 22159 Hamburg, Deutschland"), null, new Location(LocationType.ADDRESS, 0, 53734260, 9674990, null,
"Lehmkuhlen 5, 25337 Elmshorn, Deutschland"), new Date(), true, ALL_PRODUCTS, WalkSpeed.NORMAL);
System.out.println(result);
final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.context);

View file

@ -14,6 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.schildbach.pte.live;
import java.util.Date;
@ -55,8 +56,8 @@ public class KvvProviderLiveTest
@Test
public void connectionBetweenAddresses() throws Exception
{
final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.ADDRESS, 0, 48985089, 8402709,
"Konstanzer Straße 17, 76199 Karlsruhe, Deutschland"), null, new Location(LocationType.ADDRESS, 0, 49007706, 8356358,
final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.ADDRESS, 0, 48985089, 8402709, null,
"Konstanzer Straße 17, 76199 Karlsruhe, Deutschland"), null, new Location(LocationType.ADDRESS, 0, 49007706, 8356358, null,
"Durmersheimer Straße 6, 76185 Karlsruhe, Deutschland"), new Date(), true, ALL_PRODUCTS, WalkSpeed.NORMAL);
System.out.println(result);
final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.context);

View file

@ -57,8 +57,8 @@ public class MvvProviderLiveTest
@Test
public void connectionBetweenCoordinates() throws Exception
{
final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.ADDRESS, 0, 48165238, 11577473, null), null,
new Location(LocationType.ADDRESS, 0, 47987199, 11326532, null), new Date(), true, ALL_PRODUCTS, WalkSpeed.NORMAL);
final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.ADDRESS, 0, 48165238, 11577473, null, null), null,
new Location(LocationType.ADDRESS, 0, 47987199, 11326532, null, null), new Date(), true, ALL_PRODUCTS, WalkSpeed.NORMAL);
System.out.println(result);
final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.context);
System.out.println(moreResult);
@ -67,7 +67,7 @@ public class MvvProviderLiveTest
@Test
public void connectionBetweenCoordinateAndStation() throws Exception
{
final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.ADDRESS, 0, 48238341, 11478230, null), null,
final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.ADDRESS, 0, 48238341, 11478230, null, null), null,
new Location(LocationType.ANY, 0, "Ostbahnhof"), new Date(), true, ALL_PRODUCTS, WalkSpeed.NORMAL);
System.out.println(result);
final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.context);
@ -88,7 +88,7 @@ public class MvvProviderLiveTest
public void connectionBetweenStationAndAddress() throws Exception
{
final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.STATION, 1220, "Josephsburg"), null, new Location(
LocationType.ADDRESS, 0, 48188018, 11574239, "München Frankfurter Ring 35"), new Date(), true, ALL_PRODUCTS, WalkSpeed.NORMAL);
LocationType.ADDRESS, 0, 48188018, 11574239, null, "München Frankfurter Ring 35"), new Date(), true, ALL_PRODUCTS, WalkSpeed.NORMAL);
System.out.println(result);
final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.context);
System.out.println(moreResult);

View file

@ -57,7 +57,7 @@ public class TflProviderLiveTest
public void postcodeConnection() throws Exception
{
final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.ANY, 0, "sw19 8ta"), null, new Location(
LocationType.STATION, 1016019, 51655903, -397249, "Watford (Herts), Watford Town Centre"), new Date(), true, ALL_PRODUCTS,
LocationType.STATION, 1016019, 51655903, -397249, null, "Watford (Herts), Watford Town Centre"), new Date(), true, ALL_PRODUCTS,
WalkSpeed.NORMAL);
System.out.println(result);
}