mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-08 00:08:49 +00:00
AbstractHafasClientInterfaceProvider: Parse 'nameS' (short name) in 'prodL' entries.
This commit is contained in:
parent
ea652f30cc
commit
724f8a23e3
5 changed files with 36 additions and 42 deletions
|
@ -861,19 +861,42 @@ 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 nameS = prod.optString("nameS", null);
|
||||
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);
|
||||
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;
|
||||
}
|
||||
|
||||
protected Line newLine(final String operator, final Product product, final String name, final String number) {
|
||||
return new Line(null, operator, product, number, name, lineStyle(operator, product, number));
|
||||
protected Line newLine(final String operator, final Product product, final @Nullable String name,
|
||||
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")
|
||||
|
|
|
@ -22,9 +22,7 @@ import java.util.regex.Matcher;
|
|||
import java.util.regex.Pattern;
|
||||
|
||||
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 okhttp3.HttpUrl;
|
||||
|
@ -76,15 +74,4 @@ public final class BahnProvider extends AbstractHafasClientInterfaceProvider {
|
|||
return new String[] { m.group(1), m.group(2) };
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,8 @@ import java.util.Map;
|
|||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import de.schildbach.pte.dto.Fare;
|
||||
|
@ -104,8 +106,9 @@ public final class BvgProvider extends AbstractHafasClientInterfaceProvider {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Line newLine(final String operator, final Product product, final String name, final String number) {
|
||||
final Line line = super.newLine(operator, product, name, number);
|
||||
protected Line newLine(final String operator, final Product product, final @Nullable String name,
|
||||
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 ("S41".equals(line.label))
|
||||
|
|
|
@ -22,6 +22,8 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import de.schildbach.pte.dto.Line;
|
||||
|
@ -81,8 +83,9 @@ public class VbnProvider extends AbstractHafasClientInterfaceProvider {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Line newLine(final String operator, final Product product, final String name, final String number) {
|
||||
final Line line = super.newLine(operator, product, name, number);
|
||||
protected Line newLine(final String operator, final Product product, final @Nullable String name,
|
||||
final @Nullable String shortName, final @Nullable String number) {
|
||||
final Line line = super.newLine(operator, product, name, shortName, number);
|
||||
|
||||
if (line.product == Product.BUS) {
|
||||
if ("57".equals(line.label))
|
||||
|
|
|
@ -22,7 +22,6 @@ 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;
|
||||
|
@ -97,27 +96,6 @@ 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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue