ZVV: Replace some line numbers by the line name.

This commit is contained in:
Andreas Schildbach 2018-11-17 10:33:22 +01:00
parent 679915bed3
commit 28dd2c8033
3 changed files with 43 additions and 3 deletions

View file

@ -846,7 +846,7 @@ public abstract class AbstractHafasClientInterfaceProvider extends AbstractHafas
for (int iProd = 0; iProd < prodListLen; iProd++) {
final JSONObject prod = prodList.getJSONObject(iProd);
final String name = Strings.emptyToNull(prod.getString("name"));
final String number = prod.optString("number");
final String number = prod.optString("number", null);
final int oprIndex = prod.optInt("oprX", -1);
final String operator = oprIndex != -1 ? operators.get(oprIndex) : null;
final int cls = prod.optInt("cls", -1);

View file

@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 the original author or authors.
* Copyright the original author or authors.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -22,6 +22,7 @@ import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import de.schildbach.pte.dto.Line;
import de.schildbach.pte.dto.Product;
import de.schildbach.pte.dto.Style;
import de.schildbach.pte.dto.Style.Shape;
@ -93,6 +94,27 @@ public class ZvvProvider extends AbstractHafasClientInterfaceProvider {
return Product.ALL;
}
@Override
protected Line newLine(final String operator, final Product product, final String name, final String number) {
if (name == null)
return super.newLine(operator, product, name, number);
final String[] splitName = name.split("\\s+", 2);
if (splitName.length != 2)
return super.newLine(operator, product, name, number);
final String newName = name + (number != null ? " (" + number + ")" : "");
final String newNumber;
if (product == Product.BUS && "Bus".equals(splitName[0]))
newNumber = splitName[1];
else if (product == Product.BUS && "Tro".equals(splitName[0]))
newNumber = splitName[1];
else if (product == Product.TRAM && "Trm".equals(splitName[0]))
newNumber = splitName[1];
else
newNumber = splitName[0] + splitName[1];
return super.newLine(operator, product, newName, newNumber);
}
private static final Map<String, Style> STYLES = new HashMap<>();
static {

View file

@ -48,7 +48,25 @@ public class ZvvProviderLiveTest extends AbstractProviderLiveTest {
@Test
public void queryDepartures() throws Exception {
final QueryDeparturesResult result = queryDepartures("8503000", false);
final QueryDeparturesResult result = queryDepartures("8503000", false); // Hauptbahnhof
print(result);
}
@Test
public void queryDeparturesSuburbanTrain() throws Exception {
final QueryDeparturesResult result = queryDepartures("8500169", false); // Muriaux
print(result);
}
@Test
public void queryDeparturesTram() throws Exception {
final QueryDeparturesResult result = queryDepartures("8591276", false); // Milchbuck
print(result);
}
@Test
public void queryDeparturesTrolley() throws Exception {
final QueryDeparturesResult result = queryDepartures("8591177", false); // Hardplatz
print(result);
}