AbstractHafasClientInterfaceProvider: Parse 'nameS' (short name) in 'prodL' entries.

This commit is contained in:
Andreas Schildbach 2018-11-30 13:36:39 +01:00
parent ea652f30cc
commit 724f8a23e3
5 changed files with 36 additions and 42 deletions

View file

@ -861,19 +861,42 @@ public abstract class AbstractHafasClientInterfaceProvider extends AbstractHafas
for (int iProd = 0; iProd < prodListLen; iProd++) { for (int iProd = 0; iProd < prodListLen; iProd++) {
final JSONObject prod = prodList.getJSONObject(iProd); final JSONObject prod = prodList.getJSONObject(iProd);
final String name = Strings.emptyToNull(prod.getString("name")); final String name = Strings.emptyToNull(prod.getString("name"));
final String nameS = prod.optString("nameS", null);
final String number = prod.optString("number", null); final String number = prod.optString("number", null);
final int oprIndex = prod.optInt("oprX", -1); final int oprIndex = prod.optInt("oprX", -1);
final String operator = oprIndex != -1 ? operators.get(oprIndex) : null; final String operator = oprIndex != -1 ? operators.get(oprIndex) : null;
final int cls = prod.optInt("cls", -1); final int cls = prod.optInt("cls", -1);
final Product product = cls != -1 ? intToProduct(cls) : null; final Product product = cls != -1 ? intToProduct(cls) : null;
lines.add(newLine(operator, product, name, number)); lines.add(newLine(operator, product, name, nameS, number));
} }
return lines; return lines;
} }
protected Line newLine(final String operator, final Product product, final String name, final String number) { protected Line newLine(final String operator, final Product product, final @Nullable String name,
return new Line(null, operator, product, number, name, lineStyle(operator, product, number)); final @Nullable String shortName, final @Nullable String number) {
final String longName;
if (name != null)
longName = name + (number != null && !name.endsWith(number) ? " (" + number + ")" : "");
else if (shortName != null)
longName = shortName + (number != null && !shortName.endsWith(number) ? " (" + number + ")" : "");
else
longName = number;
if (product == Product.BUS || product == Product.TRAM) {
// For bus and tram, prefer a slightly shorter label without the product prefix
final String label;
if (shortName != null)
label = shortName;
else if (number != null && name != null && name.endsWith(number))
label = number;
else
label = name;
return new Line(null, operator, product, label, longName, lineStyle(operator, product, label));
} else {
// Otherwise the longer label is fine
return new Line(null, operator, product, name, longName, lineStyle(operator, product, name));
}
} }
@SuppressWarnings("serial") @SuppressWarnings("serial")

View file

@ -22,9 +22,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import com.google.common.base.Charsets; import com.google.common.base.Charsets;
import com.google.common.base.Strings;
import de.schildbach.pte.dto.Line;
import de.schildbach.pte.dto.Product; import de.schildbach.pte.dto.Product;
import okhttp3.HttpUrl; import okhttp3.HttpUrl;
@ -76,15 +74,4 @@ public final class BahnProvider extends AbstractHafasClientInterfaceProvider {
return new String[] { m.group(1), m.group(2) }; return new String[] { m.group(1), m.group(2) };
return super.splitStationName(address); return super.splitStationName(address);
} }
@Override
protected Line newLine(final String operator, final Product product, final String name, final String number) {
if (product == Product.SUBURBAN_TRAIN && name != null && name.startsWith("S")
&& !(number != null && number.startsWith("S")))
return super.newLine(operator, product, name, "S" + Strings.nullToEmpty(number));
if (product == Product.SUBWAY && name != null && name.startsWith("U")
&& !(number != null && number.startsWith("U")))
return super.newLine(operator, product, name, "U" + Strings.nullToEmpty(number));
return super.newLine(operator, product, name, number);
}
} }

View file

@ -23,6 +23,8 @@ import java.util.Map;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import javax.annotation.Nullable;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import de.schildbach.pte.dto.Fare; import de.schildbach.pte.dto.Fare;
@ -104,8 +106,9 @@ public final class BvgProvider extends AbstractHafasClientInterfaceProvider {
} }
@Override @Override
protected Line newLine(final String operator, final Product product, final String name, final String number) { protected Line newLine(final String operator, final Product product, final @Nullable String name,
final Line line = super.newLine(operator, product, name, number); final @Nullable String shortName, final @Nullable String number) {
final Line line = super.newLine(operator, product, name, shortName, number);
if (line.product == Product.SUBURBAN_TRAIN) { if (line.product == Product.SUBURBAN_TRAIN) {
if ("S41".equals(line.label)) if ("S41".equals(line.label))

View file

@ -22,6 +22,8 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import javax.annotation.Nullable;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import de.schildbach.pte.dto.Line; import de.schildbach.pte.dto.Line;
@ -81,8 +83,9 @@ public class VbnProvider extends AbstractHafasClientInterfaceProvider {
} }
@Override @Override
protected Line newLine(final String operator, final Product product, final String name, final String number) { protected Line newLine(final String operator, final Product product, final @Nullable String name,
final Line line = super.newLine(operator, product, name, number); final @Nullable String shortName, final @Nullable String number) {
final Line line = super.newLine(operator, product, name, shortName, number);
if (line.product == Product.BUS) { if (line.product == Product.BUS) {
if ("57".equals(line.label)) if ("57".equals(line.label))

View file

@ -22,7 +22,6 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import de.schildbach.pte.dto.Line;
import de.schildbach.pte.dto.Product; import de.schildbach.pte.dto.Product;
import de.schildbach.pte.dto.Style; import de.schildbach.pte.dto.Style;
import de.schildbach.pte.dto.Style.Shape; import de.schildbach.pte.dto.Style.Shape;
@ -97,27 +96,6 @@ public class ZvvProvider extends AbstractHafasClientInterfaceProvider {
return Product.ALL; 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<>(); private static final Map<String, Style> STYLES = new HashMap<>();
static { static {