parse on demand service in binary connections query

This commit is contained in:
Andreas Schildbach 2013-03-17 20:44:36 +01:00
parent 57e0492936
commit 6361096607
7 changed files with 63 additions and 50 deletions

View file

@ -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,13 +1765,24 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider
final int partAttrIndex = is.readShortReverse();
final List<Line.Attr> lineAttrs = new ArrayList<Line.Attr>();
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();
is.skipBytes(attrsOffset + partAttrIndex * 4);
@ -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<Line.Attr> attrSet = new HashSet<Line.Attr>();
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);
}
}

View file

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

View file

@ -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);
}

View file

@ -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);
}
}

View file

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

View file

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

View file

@ -56,7 +56,7 @@ public final class Line implements Serializable, Comparable<Line>
this(id, label, style, attrs, null);
}
private Line(final String id, final String label, final Style style, final Set<Attr> attrs, final String message)
public Line(final String id, final String label, final Style style, final Set<Attr> attrs, final String message)
{
this.id = id;
this.label = label;