AbstractHafasClientInterfaceProvider: Parse product numbers.

This commit is contained in:
Andreas Schildbach 2018-11-15 16:36:27 +01:00
parent 018d084b65
commit a7f6abc4b9
3 changed files with 47 additions and 47 deletions

View file

@ -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<Line> parseProdList(final JSONArray prodList, final List<String> operators) throws JSONException {
final List<Line> lines = new ArrayList<>(prodList.length());
final int prodListLen = prodList.length();
final List<Line> 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")

View file

@ -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

View file

@ -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 && "57".equals(line.label))
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 (line.product == Product.BUS && "58".equals(line.label))
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);
}
return line;
}