From 6361096607dd98eb39b216e2482b33d1383f193d Mon Sep 17 00:00:00 2001 From: Andreas Schildbach Date: Sun, 17 Mar 2013 20:44:36 +0100 Subject: [PATCH] parse on demand service in binary connections query --- .../schildbach/pte/AbstractHafasProvider.java | 63 +++++++++++-------- .../src/de/schildbach/pte/BvgProvider.java | 24 +++---- .../de/schildbach/pte/EireannProvider.java | 2 +- enabler/src/de/schildbach/pte/SeProvider.java | 6 +- .../de/schildbach/pte/StockholmProvider.java | 2 +- .../src/de/schildbach/pte/ZvvProvider.java | 14 ++--- enabler/src/de/schildbach/pte/dto/Line.java | 2 +- 7 files changed, 63 insertions(+), 50 deletions(-) diff --git a/enabler/src/de/schildbach/pte/AbstractHafasProvider.java b/enabler/src/de/schildbach/pte/AbstractHafasProvider.java index 7518dba9..d8ddc697 100644 --- a/enabler/src/de/schildbach/pte/AbstractHafasProvider.java +++ b/enabler/src/de/schildbach/pte/AbstractHafasProvider.java @@ -721,9 +721,9 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider // could check for type consistency here final String lineName = prodLine.label.substring(1); if (prodLine.attrs != null) - line = newLine(classChar, lineName, prodLine.attrs.toArray(new Line.Attr[0])); + line = newLine(classChar, lineName, null, prodLine.attrs.toArray(new Line.Attr[0])); else - line = newLine(classChar, lineName); + line = newLine(classChar, lineName, null); } else @@ -1765,12 +1765,23 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider final int partAttrIndex = is.readShortReverse(); final List lineAttrs = new ArrayList(); + String lineComment = null; + boolean lineOnDemand = false; for (final String comment : comments.read(is)) { if (comment.startsWith("bf ")) + { lineAttrs.add(Line.Attr.WHEEL_CHAIR_ACCESS); + } else if (comment.startsWith("FA ") || comment.startsWith("FB ") || comment.startsWith("FR ")) + { lineAttrs.add(Line.Attr.BICYCLE_CARRIAGE); + } + else if (comment.startsWith("$R ")) + { + lineOnDemand = true; + lineComment = comment.substring(5); + } } is.reset(); @@ -1882,12 +1893,14 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider else if (type == 2) { final char lineProduct; - if (lineClass != 0) + if (lineOnDemand) + lineProduct = Product.ON_DEMAND.code; + else if (lineClass != 0) lineProduct = intToProduct(lineClass); else lineProduct = normalizeType(lineCategory); - final Line line = newLine(lineProduct, normalizeLineName(lineName), lineAttrs.toArray(new Line.Attr[0])); + final Line line = newLine(lineProduct, normalizeLineName(lineName), lineComment, lineAttrs.toArray(new Line.Attr[0])); final Location direction = directionStr != null ? new Location(LocationType.ANY, 0, null, directionStr) : null; final Stop departure = new Stop(departureLocation, true, plannedDepartureTime != 0 ? new Date(plannedDepartureTime) @@ -2763,22 +2776,22 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider private static final Pattern P_NORMALIZE_LINE_BUS = Pattern.compile("(?:Bus|BUS)\\s*(.*)"); private static final Pattern P_NORMALIZE_LINE_TRAM = Pattern.compile("(?:Tram|Str|STR)\\s*(.*)"); - protected Line parseLine(final String type, final String line, final boolean wheelchairAccess) + protected Line parseLine(final String type, final String normalizedName, final boolean wheelchairAccess) { - if (line != null) + if (normalizedName != null) { - final Matcher mBus = P_NORMALIZE_LINE_BUS.matcher(line); + final Matcher mBus = P_NORMALIZE_LINE_BUS.matcher(normalizedName); if (mBus.matches()) - return newLine('B', mBus.group(1)); + return newLine('B', mBus.group(1), null); - final Matcher mTram = P_NORMALIZE_LINE_TRAM.matcher(line); + final Matcher mTram = P_NORMALIZE_LINE_TRAM.matcher(normalizedName); if (mTram.matches()) - return newLine('T', mTram.group(1)); + return newLine('T', mTram.group(1), null); } final char normalizedType = normalizeType(type); if (normalizedType == 0) - throw new IllegalStateException("cannot normalize type '" + type + "' line '" + line + "'"); + throw new IllegalStateException("cannot normalize type '" + type + "' line '" + normalizedName + "'"); final Line.Attr[] attrs; if (wheelchairAccess) @@ -2786,16 +2799,16 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider else attrs = new Line.Attr[0]; - if (line != null) + if (normalizedName != null) { - final Matcher m = P_NORMALIZE_LINE.matcher(line); - final String strippedLine = m.matches() ? m.group(1) + m.group(2) : line; + final Matcher m = P_NORMALIZE_LINE.matcher(normalizedName); + final String strippedLine = m.matches() ? m.group(1) + m.group(2) : normalizedName; - return newLine(normalizedType, strippedLine, attrs); + return newLine(normalizedType, strippedLine, null, attrs); } else { - return newLine(normalizedType, null, attrs); + return newLine(normalizedType, null, null, attrs); } } @@ -2816,11 +2829,11 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider if (type.length() == 0) { if (number.length() == 0) - return newLine('?', null); + return newLine('?', null, null); if (P_NORMALIZE_LINE_NUMBER.matcher(number).matches()) - return newLine('?', number); + return newLine('?', number, null); if (P_LINE_RUSSIA.matcher(number).matches()) - return newLine('R', number); + return newLine('R', number, null); } else { @@ -2831,17 +2844,17 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider { final Matcher mBus = P_NORMALIZE_LINE_BUS.matcher(number); if (mBus.matches()) - return newLine('B', mBus.group(1)); + return newLine('B', mBus.group(1), null); } if (normalizedType == 'T') { final Matcher mTram = P_NORMALIZE_LINE_TRAM.matcher(number); if (mTram.matches()) - return newLine('T', mTram.group(1)); + return newLine('T', mTram.group(1), null); } - return newLine(normalizedType, number.replaceAll("\\s+", "")); + return newLine(normalizedType, number.replaceAll("\\s+", ""), null); } } @@ -2851,20 +2864,20 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider throw new IllegalStateException("cannot normalize line#type '" + lineAndType + "'"); } - protected Line newLine(final char product, final String normalizedName, final Line.Attr... attrs) + protected Line newLine(final char product, final String normalizedName, final String comment, final Line.Attr... attrs) { final String lineStr = product + (normalizedName != null ? normalizedName : "?"); if (attrs.length == 0) { - return new Line(null, lineStr, lineStyle(lineStr)); + return new Line(null, lineStr, lineStyle(lineStr), comment); } else { final Set attrSet = new HashSet(); for (final Line.Attr attr : attrs) attrSet.add(attr); - return new Line(null, lineStr, lineStyle(lineStr), attrSet); + return new Line(null, lineStr, lineStyle(lineStr), attrSet, comment); } } diff --git a/enabler/src/de/schildbach/pte/BvgProvider.java b/enabler/src/de/schildbach/pte/BvgProvider.java index 4744e7a7..a135a7c8 100644 --- a/enabler/src/de/schildbach/pte/BvgProvider.java +++ b/enabler/src/de/schildbach/pte/BvgProvider.java @@ -353,7 +353,7 @@ public final class BvgProvider extends AbstractHafasProvider { final String lineName = ParserUtils.resolveEntities(mMsgsFine.group(1)); final char linePproduct = normalizeType(categoryFromName(lineName)); - final Line line = newLine(linePproduct, normalizeLineName(lineName)); + final Line line = newLine(linePproduct, normalizeLineName(lineName), null); final String message = ParserUtils.resolveEntities(mMsgsFine.group(3)).replace('\n', ' '); messages.put(line.label, message); @@ -390,7 +390,7 @@ public final class BvgProvider extends AbstractHafasProvider final String lineName = ParserUtils.resolveEntities(mDepFine.group(3)); final char lineProduct = normalizeType(categoryFromName(lineName)); - final Line line = newLine(lineProduct, normalizeLineName(lineName)); + final Line line = newLine(lineProduct, normalizeLineName(lineName), null); final String position = null; @@ -462,7 +462,7 @@ public final class BvgProvider extends AbstractHafasProvider final String lineName = ParserUtils.resolveEntities(mDepFine.group(2)); final char lineProduct = normalizeType(categoryFromName(lineName)); - final Line line = newLine(lineProduct, normalizeLineName(lineName)); + final Line line = newLine(lineProduct, normalizeLineName(lineName), null); final String position = ParserUtils.resolveEntities(mDepFine.group(3)); @@ -555,26 +555,26 @@ public final class BvgProvider extends AbstractHafasProvider } @Override - protected Line newLine(final char product, final String normalizedName, final Attr... attrs) + protected Line newLine(final char product, final String normalizedName, final String comment, final Attr... attrs) { if (product == 'S' && "S41".equals(normalizedName)) - return super.newLine(product, normalizedName, concatAttrs(attrs, Attr.CIRCLE_CLOCKWISE)); + return super.newLine(product, normalizedName, comment, concatAttrs(attrs, Attr.CIRCLE_CLOCKWISE)); if (product == 'S' && "S42".equals(normalizedName)) - return super.newLine(product, normalizedName, concatAttrs(attrs, Attr.CIRCLE_ANTICLOCKWISE)); + return super.newLine(product, normalizedName, comment, concatAttrs(attrs, Attr.CIRCLE_ANTICLOCKWISE)); if (product == 'B' && "S41".equals(normalizedName)) - return super.newLine(product, normalizedName, concatAttrs(attrs, Attr.SERVICE_REPLACEMENT, Attr.CIRCLE_CLOCKWISE)); + return super.newLine(product, normalizedName, comment, concatAttrs(attrs, Attr.SERVICE_REPLACEMENT, Attr.CIRCLE_CLOCKWISE)); if (product == 'B' && "S42".equals(normalizedName)) - return super.newLine(product, normalizedName, concatAttrs(attrs, Attr.SERVICE_REPLACEMENT, Attr.CIRCLE_ANTICLOCKWISE)); + return super.newLine(product, normalizedName, comment, concatAttrs(attrs, Attr.SERVICE_REPLACEMENT, Attr.CIRCLE_ANTICLOCKWISE)); if (product == 'B' && "TXL".equals(normalizedName)) - return super.newLine(product, normalizedName, concatAttrs(attrs, Attr.LINE_AIRPORT)); + return super.newLine(product, normalizedName, comment, concatAttrs(attrs, Attr.LINE_AIRPORT)); if (product == 'S' && "S9".equals(normalizedName)) - return super.newLine(product, normalizedName, concatAttrs(attrs, Attr.LINE_AIRPORT)); + return super.newLine(product, normalizedName, comment, concatAttrs(attrs, Attr.LINE_AIRPORT)); if (product == 'S' && "S45".equals(normalizedName)) - return super.newLine(product, normalizedName, concatAttrs(attrs, Attr.LINE_AIRPORT)); + return super.newLine(product, normalizedName, comment, concatAttrs(attrs, Attr.LINE_AIRPORT)); - return super.newLine(product, normalizedName, attrs); + return super.newLine(product, normalizedName, comment, attrs); } private Attr[] concatAttrs(final Attr[] attrs1, final Attr... attrs2) diff --git a/enabler/src/de/schildbach/pte/EireannProvider.java b/enabler/src/de/schildbach/pte/EireannProvider.java index e512fbed..3adf5e32 100644 --- a/enabler/src/de/schildbach/pte/EireannProvider.java +++ b/enabler/src/de/schildbach/pte/EireannProvider.java @@ -161,7 +161,7 @@ public class EireannProvider extends AbstractHafasProvider { final Matcher mLine = P_NORMALIZE_LINE.matcher(lineAndType); if (mLine.matches()) - return newLine('B', mLine.group(1)); + return newLine('B', mLine.group(1), null); return super.parseLineAndType(lineAndType); } diff --git a/enabler/src/de/schildbach/pte/SeProvider.java b/enabler/src/de/schildbach/pte/SeProvider.java index 14b67e65..8adaca0c 100644 --- a/enabler/src/de/schildbach/pte/SeProvider.java +++ b/enabler/src/de/schildbach/pte/SeProvider.java @@ -216,12 +216,12 @@ public class SeProvider extends AbstractHafasProvider { final Matcher mBus = P_NORMALIZE_LINE_BUS.matcher(line); if (mBus.matches()) - return newLine('B', mBus.group(1)); + return newLine('B', mBus.group(1), null); final Matcher mSubway = P_NORMALIZE_LINE_SUBWAY.matcher(line); if (mSubway.matches()) - return newLine('U', "T" + mSubway.group(1)); + return newLine('U', "T" + mSubway.group(1), null); - return newLine('?', line); + return newLine('?', line, null); } } diff --git a/enabler/src/de/schildbach/pte/StockholmProvider.java b/enabler/src/de/schildbach/pte/StockholmProvider.java index 59f7c0d8..bedafee5 100644 --- a/enabler/src/de/schildbach/pte/StockholmProvider.java +++ b/enabler/src/de/schildbach/pte/StockholmProvider.java @@ -201,7 +201,7 @@ public class StockholmProvider extends AbstractHafasProvider { final char normalizedType = normalizeType(type); if (normalizedType != 0) - return newLine(normalizedType, number); + return newLine(normalizedType, number, null); } throw new IllegalStateException("cannot normalize type " + type + " number " + number + " line#type " + lineAndType); diff --git a/enabler/src/de/schildbach/pte/ZvvProvider.java b/enabler/src/de/schildbach/pte/ZvvProvider.java index f07cd928..813f4854 100644 --- a/enabler/src/de/schildbach/pte/ZvvProvider.java +++ b/enabler/src/de/schildbach/pte/ZvvProvider.java @@ -223,23 +223,23 @@ public class ZvvProvider extends AbstractHafasProvider final String type = m.group(2); if ("Bus".equals(type)) - return newLine('B', stripPrefix(number, "Bus")); + return newLine('B', stripPrefix(number, "Bus"), null); if ("Bus-NF".equals(type)) - return newLine('B', stripPrefix(number, "Bus", "Bus-NF"), Line.Attr.WHEEL_CHAIR_ACCESS); + return newLine('B', stripPrefix(number, "Bus", "Bus-NF"), null, Line.Attr.WHEEL_CHAIR_ACCESS); if ("Tro".equals(type) || "Trolley".equals(type)) - return newLine('B', stripPrefix(number, "Tro")); + return newLine('B', stripPrefix(number, "Tro"), null); if ("Tro-NF".equals(type)) - return newLine('B', stripPrefix(number, "Tro", "Tro-NF"), Line.Attr.WHEEL_CHAIR_ACCESS); + return newLine('B', stripPrefix(number, "Tro", "Tro-NF"), null, Line.Attr.WHEEL_CHAIR_ACCESS); if ("Trm".equals(type)) - return newLine('T', stripPrefix(number, "Trm")); + return newLine('T', stripPrefix(number, "Trm"), null); if ("Trm-NF".equals(type)) - return newLine('T', stripPrefix(number, "Trm", "Trm-NF"), Line.Attr.WHEEL_CHAIR_ACCESS); + return newLine('T', stripPrefix(number, "Trm", "Trm-NF"), null, Line.Attr.WHEEL_CHAIR_ACCESS); if (type.length() > 0) { final char normalizedType = normalizeType(type); if (normalizedType != 0) - return newLine(normalizedType, number); + return newLine(normalizedType, number, null); } throw new IllegalStateException("cannot normalize type " + type + " number " + number + " line#type " + lineAndType); diff --git a/enabler/src/de/schildbach/pte/dto/Line.java b/enabler/src/de/schildbach/pte/dto/Line.java index 8dfd7e4a..2ddbaec5 100644 --- a/enabler/src/de/schildbach/pte/dto/Line.java +++ b/enabler/src/de/schildbach/pte/dto/Line.java @@ -56,7 +56,7 @@ public final class Line implements Serializable, Comparable this(id, label, style, attrs, null); } - private Line(final String id, final String label, final Style style, final Set attrs, final String message) + public Line(final String id, final String label, final Style style, final Set attrs, final String message) { this.id = id; this.label = label;