From a7f6abc4b988e3e87b1a29a7cd8f08f38ff8e056 Mon Sep 17 00:00:00 2001 From: Andreas Schildbach Date: Thu, 15 Nov 2018 16:36:27 +0100 Subject: [PATCH] AbstractHafasClientInterfaceProvider: Parse product numbers. --- .../AbstractHafasClientInterfaceProvider.java | 24 ++++----- .../src/de/schildbach/pte/BvgProvider.java | 51 ++++++++++--------- .../src/de/schildbach/pte/VbnProvider.java | 19 ++++--- 3 files changed, 47 insertions(+), 47 deletions(-) diff --git a/enabler/src/de/schildbach/pte/AbstractHafasClientInterfaceProvider.java b/enabler/src/de/schildbach/pte/AbstractHafasClientInterfaceProvider.java index 9211b115..03f18b19 100644 --- a/enabler/src/de/schildbach/pte/AbstractHafasClientInterfaceProvider.java +++ b/enabler/src/de/schildbach/pte/AbstractHafasClientInterfaceProvider.java @@ -45,6 +45,7 @@ import org.json.JSONObject; import com.google.common.base.Charsets; import com.google.common.base.Joiner; +import com.google.common.base.Strings; import com.google.common.hash.HashCode; import com.google.common.hash.HashFunction; import com.google.common.hash.Hashing; @@ -823,32 +824,25 @@ public abstract class AbstractHafasClientInterfaceProvider extends AbstractHafas } private List parseProdList(final JSONArray prodList, final List operators) throws JSONException { - final List lines = new ArrayList<>(prodList.length()); + final int prodListLen = prodList.length(); + final List lines = new ArrayList<>(prodListLen); - for (int iProd = 0; iProd < prodList.length(); iProd++) { + 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 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; - final String name = prod.getString("name"); - lines.add(newLine(operator, product, name)); + lines.add(newLine(operator, product, name, number)); } return lines; } - protected Line newLine(final String operator, final Product product, final String name) { - final String normalizedName; - if (product == Product.BUS && name.startsWith("Bus ")) - normalizedName = name.substring(4); - else if (product == Product.TRAM && name.startsWith("Tram ")) - normalizedName = name.substring(5); - else if (product == Product.SUBURBAN_TRAIN && name.startsWith("S ")) - normalizedName = "S" + name.substring(2); - else - normalizedName = name; - return new Line(null, operator, product, normalizedName, lineStyle(operator, product, normalizedName)); + 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)); } @SuppressWarnings("serial") diff --git a/enabler/src/de/schildbach/pte/BvgProvider.java b/enabler/src/de/schildbach/pte/BvgProvider.java index b2fbc41c..4be44688 100644 --- a/enabler/src/de/schildbach/pte/BvgProvider.java +++ b/enabler/src/de/schildbach/pte/BvgProvider.java @@ -104,32 +104,35 @@ public final class BvgProvider extends AbstractHafasClientInterfaceProvider { } @Override - protected Line newLine(final String operator, final Product product, final String name) { - if (product == Product.SUBURBAN_TRAIN && "S41".equals(name)) - return new Line(null, operator, product, name, lineStyle(operator, product, name), - Sets.newHashSet(Attr.CIRCLE_CLOCKWISE)); - if (product == Product.SUBURBAN_TRAIN && "S42".equals(name)) - return new Line(null, operator, product, name, lineStyle(operator, product, name), - Sets.newHashSet(Attr.CIRCLE_ANTICLOCKWISE)); + protected Line newLine(final String operator, final Product product, final String name, final String number) { + final Line line = super.newLine(operator, product, name, number); - if (product == Product.BUS && "S41".equals(name)) - return new Line(null, operator, product, name, lineStyle(operator, product, name), - Sets.newHashSet(Attr.SERVICE_REPLACEMENT, Attr.CIRCLE_CLOCKWISE)); - if (product == Product.BUS && "S42".equals(name)) - return new Line(null, operator, product, name, lineStyle(operator, product, name), - Sets.newHashSet(Attr.SERVICE_REPLACEMENT, Attr.CIRCLE_ANTICLOCKWISE)); + if (line.product == Product.SUBURBAN_TRAIN) { + if ("S41".equals(line.label)) + return new Line(null, line.network, line.product, line.label, line.name, line.style, + Sets.newHashSet(Attr.CIRCLE_CLOCKWISE), line.message); + if ("S42".equals(line.label)) + return new Line(null, line.network, line.product, line.label, line.name, line.style, + Sets.newHashSet(Attr.CIRCLE_ANTICLOCKWISE), line.message); + if ("S9".equals(line.label)) + return new Line(null, line.network, line.product, line.label, line.name, line.style, + Sets.newHashSet(Attr.LINE_AIRPORT), line.message); + if ("S45".equals(line.label)) + return new Line(null, line.network, line.product, line.label, line.name, line.style, + Sets.newHashSet(Attr.LINE_AIRPORT), line.message); + } else if (line.product == Product.BUS) { + if ("S41".equals(line.label)) + return new Line(null, line.network, line.product, line.label, line.name, line.style, + Sets.newHashSet(Attr.SERVICE_REPLACEMENT, Attr.CIRCLE_CLOCKWISE), line.message); + if ("S42".equals(line.label)) + return new Line(null, line.network, line.product, line.label, line.name, line.style, + Sets.newHashSet(Attr.SERVICE_REPLACEMENT, Attr.CIRCLE_ANTICLOCKWISE), line.message); + if ("TXL".equals(line.label)) + return new Line(null, line.network, line.product, line.label, line.name, line.style, + Sets.newHashSet(Attr.LINE_AIRPORT), line.message); + } - if (product == Product.BUS && "TXL".equals(name)) - return new Line(null, operator, product, name, lineStyle(operator, product, name), - Sets.newHashSet(Attr.LINE_AIRPORT)); - if (product == Product.SUBURBAN_TRAIN && "S9".equals(name)) - return new Line(null, operator, product, name, lineStyle(operator, product, name), - Sets.newHashSet(Attr.LINE_AIRPORT)); - if (product == Product.SUBURBAN_TRAIN && "S45".equals(name)) - return new Line(null, operator, product, name, lineStyle(operator, product, name), - Sets.newHashSet(Attr.LINE_AIRPORT)); - - return super.newLine(operator, product, name); + return line; } @Override diff --git a/enabler/src/de/schildbach/pte/VbnProvider.java b/enabler/src/de/schildbach/pte/VbnProvider.java index c7ba8174..7049635c 100644 --- a/enabler/src/de/schildbach/pte/VbnProvider.java +++ b/enabler/src/de/schildbach/pte/VbnProvider.java @@ -81,15 +81,18 @@ public class VbnProvider extends AbstractHafasClientInterfaceProvider { } @Override - protected Line newLine(final String operator, final Product product, final String name) { - final Line line = super.newLine(operator, product, name); + protected Line newLine(final String operator, final Product product, final String name, final String number) { + final Line line = super.newLine(operator, product, name, number); + + if (line.product == Product.BUS) { + if ("57".equals(line.label)) + return new Line(null, line.network, line.product, line.label, line.name, line.style, + Sets.newHashSet(Attr.SERVICE_REPLACEMENT, Attr.CIRCLE_CLOCKWISE), line.message); + if ("58".equals(line.label)) + return new Line(null, line.network, line.product, line.label, line.name, line.style, + Sets.newHashSet(Attr.SERVICE_REPLACEMENT, Attr.CIRCLE_ANTICLOCKWISE), line.message); + } - if (line.product == Product.BUS && "57".equals(line.label)) - return new Line(null, line.network, line.product, line.label, line.name, line.style, - Sets.newHashSet(Attr.SERVICE_REPLACEMENT, Attr.CIRCLE_CLOCKWISE), line.message); - if (line.product == Product.BUS && "58".equals(line.label)) - return new Line(null, line.network, line.product, line.label, line.name, line.style, - Sets.newHashSet(Attr.SERVICE_REPLACEMENT, Attr.CIRCLE_ANTICLOCKWISE), line.message); return line; }