From 611814cb88bf79b51f42909dca27b63fc337333c Mon Sep 17 00:00:00 2001 From: Andreas Schildbach Date: Mon, 14 May 2012 15:46:43 +0200 Subject: [PATCH] fixed negative destination location ids --- .../de/schildbach/pte/AbstractEfaProvider.java | 18 +++++++++--------- .../src/de/schildbach/pte/dto/Location.java | 14 ++++++++++++++ .../pte/live/BsvagProviderLiveTest.java | 9 +++++++++ 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/enabler/src/de/schildbach/pte/AbstractEfaProvider.java b/enabler/src/de/schildbach/pte/AbstractEfaProvider.java index 56d6a09d..f0251725 100644 --- a/enabler/src/de/schildbach/pte/AbstractEfaProvider.java +++ b/enabler/src/de/schildbach/pte/AbstractEfaProvider.java @@ -1359,9 +1359,8 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider final String destinationIdStr = pp.getAttributeValue(null, "destID"); final int destinationId = (destinationIdStr != null && destinationIdStr.length() > 0) ? Integer.parseInt(destinationIdStr) : 0; - - final Location destination = new Location(destinationId > 0 ? LocationType.STATION : LocationType.ANY, destinationId, null, - destinationName); + final Location destination = new Location(destinationId > 0 ? LocationType.STATION : LocationType.ANY, + destinationId > 0 ? destinationId : 0, null, destinationName); final LineDestination line = new LineDestination(processItdServingLine(pp), destination); StationDepartures assignedStationDepartures; @@ -1430,9 +1429,8 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider final String destinationName = normalizeLocationName(pp.getAttributeValue(null, "direction")); final String destinationIdStr = pp.getAttributeValue(null, "destID"); final int destinationId = destinationIdStr != null ? Integer.parseInt(destinationIdStr) : 0; - - final Location destination = new Location(destinationId > 0 ? LocationType.STATION : LocationType.ANY, destinationId, null, - destinationName); + final Location destination = new Location(destinationId > 0 ? LocationType.STATION : LocationType.ANY, + destinationId > 0 ? destinationId : 0, null, destinationName); final Line line = processItdServingLine(pp); if (isRealtime && !predictedDepartureTime.isSet(Calendar.HOUR_OF_DAY)) @@ -1980,10 +1978,12 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider } else { - final String destinationIdStr = pp.getAttributeValue(null, "destID"); final String destinationName = normalizeLocationName(pp.getAttributeValue(null, "destination")); - final Location destination = destinationIdStr.length() > 0 ? new Location(LocationType.STATION, - Integer.parseInt(destinationIdStr), null, destinationName) : new Location(LocationType.ANY, 0, null, destinationName); + final String destinationIdStr = pp.getAttributeValue(null, "destID"); + final int destinationId = (destinationIdStr != null && destinationIdStr.length() > 0) ? Integer.parseInt(destinationIdStr) + : 0; + final Location destination = new Location(destinationId > 0 ? LocationType.STATION : LocationType.ANY, + destinationId > 0 ? destinationId : 0, null, destinationName); final String lineLabel; if ("AST".equals(pp.getAttributeValue(null, "symbol"))) lineLabel = "BAST"; diff --git a/enabler/src/de/schildbach/pte/dto/Location.java b/enabler/src/de/schildbach/pte/dto/Location.java index d0f15f62..ad02102f 100644 --- a/enabler/src/de/schildbach/pte/dto/Location.java +++ b/enabler/src/de/schildbach/pte/dto/Location.java @@ -35,6 +35,8 @@ public final class Location implements Serializable public Location(final LocationType type, final int id, final int lat, final int lon, final String place, final String name) { + assertId(id); + this.type = type; this.id = id; this.lat = lat; @@ -45,6 +47,8 @@ public final class Location implements Serializable public Location(final LocationType type, final int id, final String place, final String name) { + assertId(id); + this.type = type; this.id = id; this.lat = 0; @@ -55,6 +59,8 @@ public final class Location implements Serializable public Location(final LocationType type, final int id, final int lat, final int lon) { + assertId(id); + this.type = type; this.id = id; this.lat = lat; @@ -65,6 +71,8 @@ public final class Location implements Serializable public Location(final LocationType type, final int id) { + assertId(id); + this.type = type; this.id = id; this.lat = 0; @@ -175,4 +183,10 @@ public final class Location implements Serializable return 0; return o.hashCode(); } + + private static void assertId(final int id) + { + if (id < 0) + throw new IllegalStateException("assert failed: id=" + id); + } } diff --git a/enabler/test/de/schildbach/pte/live/BsvagProviderLiveTest.java b/enabler/test/de/schildbach/pte/live/BsvagProviderLiveTest.java index 9ea5cf96..d10c0c63 100644 --- a/enabler/test/de/schildbach/pte/live/BsvagProviderLiveTest.java +++ b/enabler/test/de/schildbach/pte/live/BsvagProviderLiveTest.java @@ -29,6 +29,7 @@ import de.schildbach.pte.dto.Location; import de.schildbach.pte.dto.LocationType; import de.schildbach.pte.dto.NearbyStationsResult; import de.schildbach.pte.dto.QueryConnectionsResult; +import de.schildbach.pte.dto.QueryDeparturesResult; /** * @author Andreas Schildbach @@ -56,6 +57,14 @@ public class BsvagProviderLiveTest extends AbstractProviderLiveTest print(result); } + @Test + public void queryDepartures() throws Exception + { + final QueryDeparturesResult result = provider.queryDepartures(26000256, 0, false); + + print(result); + } + @Test public void autocompleteIncomplete() throws Exception {