fixed negative destination location ids

This commit is contained in:
Andreas Schildbach 2012-05-14 15:46:43 +02:00
parent df73454367
commit 611814cb88
3 changed files with 32 additions and 9 deletions

View file

@ -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";

View file

@ -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);
}
}

View file

@ -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
{