mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-15 00:50:31 +00:00
VRS: Fix NumberFormatException on empty polygon in queryTrips.
This commit is contained in:
parent
584c573c37
commit
e71f33ff14
2 changed files with 49 additions and 30 deletions
|
@ -118,12 +118,12 @@ public class VrsProvider extends AbstractNetworkProvider
|
|||
|
||||
public Date getLastDeparture()
|
||||
{
|
||||
return lastDeparture;
|
||||
return this.lastDeparture;
|
||||
}
|
||||
|
||||
public Date getFirstArrival()
|
||||
{
|
||||
return firstArrival;
|
||||
return this.firstArrival;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -837,7 +837,7 @@ public class VrsProvider extends AbstractNetworkProvider
|
|||
arrivalPlanned = parseDateTime(segment.getString("arrival"));
|
||||
if (j == segments.length() - 1)
|
||||
{
|
||||
context.arrival(arrivalPlanned); // TODO only last segment!!
|
||||
context.arrival(arrivalPlanned);
|
||||
}
|
||||
}
|
||||
long traveltime = segment.getLong("traveltime");
|
||||
|
@ -939,13 +939,17 @@ public class VrsProvider extends AbstractNetworkProvider
|
|||
}
|
||||
}
|
||||
|
||||
protected void parsePolygon(final String polygonStr, final List<Point> polygonArr)
|
||||
protected static void parsePolygon(final String polygonStr, final List<Point> polygonArr)
|
||||
{
|
||||
String pointsArr[] = polygonStr.split("\\s");
|
||||
for (String point : pointsArr)
|
||||
if (polygonStr != null && !polygonStr.isEmpty())
|
||||
{
|
||||
String latlon[] = point.split(",");
|
||||
polygonArr.add(new Point((int) Math.round(Double.parseDouble(latlon[0]) * 1E6), (int) Math.round(Double.parseDouble(latlon[1]) * 1E6)));
|
||||
String pointsArr[] = polygonStr.split("\\s");
|
||||
for (String point : pointsArr)
|
||||
{
|
||||
String latlon[] = point.split(",");
|
||||
polygonArr
|
||||
.add(new Point((int) Math.round(Double.parseDouble(latlon[0]) * 1E6), (int) Math.round(Double.parseDouble(latlon[1]) * 1E6)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -979,7 +983,7 @@ public class VrsProvider extends AbstractNetworkProvider
|
|||
return new Point[] { new Point(50937531, 6960279) };
|
||||
}
|
||||
|
||||
private Product productFromLineNumber(String number)
|
||||
private static Product productFromLineNumber(String number)
|
||||
{
|
||||
if (number.startsWith("I") || number.startsWith("E"))
|
||||
{
|
||||
|
@ -1012,11 +1016,10 @@ public class VrsProvider extends AbstractNetworkProvider
|
|||
final String number = processLineNumber(line.getString("number"));
|
||||
final Product productObj = parseProduct(line.getString("product"), number);
|
||||
final Style style = lineStyle("vrs", productObj, number);
|
||||
// style.foregroundColor & 0xFFFFFF, style.borderColor & 0xFFFFFF);
|
||||
return new Line(null /* id=? */, NetworkId.VRS.toString(), productObj, number, style);
|
||||
return new Line(null /* id */, NetworkId.VRS.toString(), productObj, number, style);
|
||||
}
|
||||
|
||||
private String processLineNumber(final String number)
|
||||
private static String processLineNumber(final String number)
|
||||
{
|
||||
if (number.startsWith("AST ") || number.startsWith("VRM ") || number.startsWith("VRR "))
|
||||
{
|
||||
|
@ -1036,7 +1039,7 @@ public class VrsProvider extends AbstractNetworkProvider
|
|||
}
|
||||
}
|
||||
|
||||
private Product parseProduct(String product, String number)
|
||||
private static Product parseProduct(String product, String number)
|
||||
{
|
||||
if (product.equals("LongDistanceTrains"))
|
||||
{
|
||||
|
@ -1078,7 +1081,7 @@ public class VrsProvider extends AbstractNetworkProvider
|
|||
}
|
||||
}
|
||||
|
||||
private String generateProducts(Set<Product> products)
|
||||
private static String generateProducts(Set<Product> products)
|
||||
{
|
||||
StringBuilder ret = new StringBuilder();
|
||||
Iterator<Product> it = products.iterator();
|
||||
|
@ -1095,7 +1098,7 @@ public class VrsProvider extends AbstractNetworkProvider
|
|||
return ret.toString();
|
||||
}
|
||||
|
||||
private String generateProduct(Product product)
|
||||
private static String generateProduct(Product product)
|
||||
{
|
||||
switch (product)
|
||||
{
|
||||
|
@ -1119,11 +1122,12 @@ public class VrsProvider extends AbstractNetworkProvider
|
|||
return "LightRail,Underground";
|
||||
case TRAM:
|
||||
return "LightRail";
|
||||
default:
|
||||
throw new IllegalArgumentException("unknown product: '" + product + "'");
|
||||
}
|
||||
throw new IllegalArgumentException("unknown product: '" + product + "'");
|
||||
}
|
||||
|
||||
public LocationWithPosition parseLocationAndPosition(JSONObject location) throws JSONException
|
||||
public static LocationWithPosition parseLocationAndPosition(JSONObject location) throws JSONException
|
||||
{
|
||||
final LocationType locationType;
|
||||
String id = null;
|
||||
|
@ -1190,7 +1194,7 @@ public class VrsProvider extends AbstractNetworkProvider
|
|||
}
|
||||
else if (loc.lat != 0 && loc.lon != 0)
|
||||
{
|
||||
return String.format(Locale.ENGLISH, "%f,%f", (double) loc.lat / 1E6, (double) loc.lon / 1E6);
|
||||
return String.format(Locale.ENGLISH, "%f,%f", loc.lat / 1E6, loc.lon / 1E6);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1208,7 +1212,7 @@ public class VrsProvider extends AbstractNetworkProvider
|
|||
}
|
||||
}
|
||||
|
||||
private final void appendDate(final StringBuilder uri, final Date time)
|
||||
private final static void appendDate(final StringBuilder uri, final Date time)
|
||||
{
|
||||
final Calendar c = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
|
||||
c.setTime(time);
|
||||
|
@ -1221,7 +1225,7 @@ public class VrsProvider extends AbstractNetworkProvider
|
|||
uri.append(ParserUtils.urlEncode(String.format(Locale.ENGLISH, "%04d-%02d-%02dT%02d:%02d:%02dZ", year, month, day, hour, minute, second)));
|
||||
}
|
||||
|
||||
private final Date parseDateTime(final String dateTimeStr) throws ParseException
|
||||
private final static Date parseDateTime(final String dateTimeStr) throws ParseException
|
||||
{
|
||||
return new SimpleDateFormat("yyyy-MM-dd'T'kk:mm:ssZ").parse(dateTimeStr.substring(0, dateTimeStr.lastIndexOf(':')) + "00");
|
||||
}
|
||||
|
|
|
@ -49,7 +49,9 @@ import de.schildbach.pte.dto.Product;
|
|||
import de.schildbach.pte.dto.QueryDeparturesResult;
|
||||
import de.schildbach.pte.dto.QueryTripsResult;
|
||||
import de.schildbach.pte.dto.StationDepartures;
|
||||
import de.schildbach.pte.dto.Style;
|
||||
import de.schildbach.pte.dto.SuggestLocationsResult;
|
||||
import de.schildbach.pte.util.Iso8601Format;
|
||||
|
||||
/**
|
||||
* @author Michael Dyrna
|
||||
|
@ -140,7 +142,7 @@ public class VrsProviderLiveTest extends AbstractProviderLiveTest
|
|||
assertEquals(0, result.locations.size());
|
||||
}
|
||||
|
||||
private void printLineDestinations(final QueryDeparturesResult result)
|
||||
private static void printLineDestinations(final QueryDeparturesResult result)
|
||||
{
|
||||
for (StationDepartures stationDepartures : result.stationDepartures)
|
||||
{
|
||||
|
@ -422,12 +424,11 @@ public class VrsProviderLiveTest extends AbstractProviderLiveTest
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testTripByAddress() throws Exception
|
||||
public void testTripByAddressAndEmptyPolygon() throws Exception
|
||||
{
|
||||
final QueryTripsResult result = queryTrips(new Location(LocationType.ADDRESS, null /* id */, 50740530, 7129200, "Bonn-Beuel",
|
||||
"Siegburger Str. 26"), null,
|
||||
new Location(LocationType.ADDRESS, null /* id */, 50933930, 6932440, "Köln-Neustadt-Süd", "Lützowstr. 41"), new Date(), true,
|
||||
Product.ALL, WalkSpeed.NORMAL, Accessibility.NEUTRAL);
|
||||
final QueryTripsResult result = queryTrips(new Location(LocationType.ADDRESS, null /* id */, 50909350, 6676310, "Kerpen-Sindorf",
|
||||
"Erftstraße 43"), null, new Location(LocationType.ADDRESS, null /* id */, 50923000, 6818440, "Frechen", "Zedernweg 1"),
|
||||
Iso8601Format.parseDateTime("2015-03-17 21:11:18"), true, Product.ALL, WalkSpeed.NORMAL, Accessibility.NEUTRAL);
|
||||
print(result);
|
||||
assertEquals(QueryTripsResult.Status.OK, result.status);
|
||||
assertTrue(result.trips.size() > 0);
|
||||
|
@ -526,13 +527,16 @@ public class VrsProviderLiveTest extends AbstractProviderLiveTest
|
|||
int lat = latFrom + rand.nextInt(latTo - latFrom);
|
||||
int lon = lonFrom + rand.nextInt(lonTo - lonFrom);
|
||||
System.out.println(i + " " + lat + " " + lon);
|
||||
NearbyLocationsResult result = queryNearbyLocations(EnumSet.of(LocationType.STATION), new Location(LocationType.STATION, lat, lon), 0, 1);
|
||||
stations.addAll(result.locations);
|
||||
NearbyLocationsResult result = queryNearbyLocations(EnumSet.of(LocationType.STATION), new Location(LocationType.STATION, lat, lon), 0, 3);
|
||||
if (result.status == NearbyLocationsResult.Status.OK)
|
||||
{
|
||||
stations.addAll(result.locations);
|
||||
}
|
||||
}
|
||||
Set<Line> lines = new TreeSet<Line>();
|
||||
for (Location station : stations)
|
||||
{
|
||||
QueryDeparturesResult qdr = queryDepartures(station.id, false);
|
||||
QueryDeparturesResult qdr = provider.queryDepartures(station.id, Iso8601Format.parseDateTime("2015-03-16 02:00:00"), 100, false);
|
||||
if (qdr.status == QueryDeparturesResult.Status.OK)
|
||||
{
|
||||
for (StationDepartures stationDepartures : qdr.stationDepartures)
|
||||
|
@ -555,7 +559,18 @@ public class VrsProviderLiveTest extends AbstractProviderLiveTest
|
|||
}
|
||||
for (Line line : lines)
|
||||
{
|
||||
System.out.println(line.toString());
|
||||
final Product product = line.product;
|
||||
if (product != null)
|
||||
{
|
||||
if (product.equals(Product.BUS))
|
||||
{
|
||||
final Style style = line.style;
|
||||
if (style != null)
|
||||
{
|
||||
System.out.printf("%s %6x\n", line.label, style.backgroundColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue