newLine() method now responsible for assembling line product and name

This commit is contained in:
Andreas Schildbach 2012-08-15 15:18:39 +02:00
parent 28869b00df
commit 7d64ef647f
9 changed files with 52 additions and 51 deletions

View file

@ -51,6 +51,7 @@ import org.xmlpull.v1.XmlPullParserFactory;
import de.schildbach.pte.dto.Connection; import de.schildbach.pte.dto.Connection;
import de.schildbach.pte.dto.Departure; import de.schildbach.pte.dto.Departure;
import de.schildbach.pte.dto.Line; import de.schildbach.pte.dto.Line;
import de.schildbach.pte.dto.Line.Attr;
import de.schildbach.pte.dto.Location; import de.schildbach.pte.dto.Location;
import de.schildbach.pte.dto.LocationType; import de.schildbach.pte.dto.LocationType;
import de.schildbach.pte.dto.NearbyStationsResult; import de.schildbach.pte.dto.NearbyStationsResult;
@ -2636,36 +2637,34 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider
{ {
final Matcher mBus = P_NORMALIZE_LINE_BUS.matcher(line); final Matcher mBus = P_NORMALIZE_LINE_BUS.matcher(line);
if (mBus.matches()) if (mBus.matches())
return newLine('B' + mBus.group(1)); return newLine('B', mBus.group(1));
final Matcher mTram = P_NORMALIZE_LINE_TRAM.matcher(line); final Matcher mTram = P_NORMALIZE_LINE_TRAM.matcher(line);
if (mTram.matches()) if (mTram.matches())
return newLine('T' + mTram.group(1)); return newLine('T', mTram.group(1));
} }
final char normalizedType = normalizeType(type); final char normalizedType = normalizeType(type);
if (normalizedType == 0) if (normalizedType == 0)
throw new IllegalStateException("cannot normalize type '" + type + "' line '" + line + "'"); throw new IllegalStateException("cannot normalize type '" + type + "' line '" + line + "'");
final String lineStr; final Attr[] attrs;
if (wheelchairAccess)
attrs = new Attr[] { Line.Attr.WHEEL_CHAIR_ACCESS };
else
attrs = new Attr[0];
if (line != null) if (line != null)
{ {
final Matcher m = P_NORMALIZE_LINE.matcher(line); final Matcher m = P_NORMALIZE_LINE.matcher(line);
final String strippedLine = m.matches() ? m.group(1) + m.group(2) : line; final String strippedLine = m.matches() ? m.group(1) + m.group(2) : line;
lineStr = normalizedType + strippedLine; return newLine(normalizedType, strippedLine, attrs);
// FIXME xxxxxxx
} }
else else
{ {
lineStr = Character.toString(normalizedType); return newLine(normalizedType, null, attrs);
} }
if (wheelchairAccess)
return newLine(lineStr, Line.Attr.WHEEL_CHAIR_ACCESS);
else
return newLine(lineStr);
} }
protected Line parseLineWithoutType(final String line) protected Line parseLineWithoutType(final String line)
@ -2675,11 +2674,11 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider
final Matcher mBus = P_NORMALIZE_LINE_BUS.matcher(line); final Matcher mBus = P_NORMALIZE_LINE_BUS.matcher(line);
if (mBus.matches()) if (mBus.matches())
return newLine('B' + mBus.group(1)); return newLine('B', mBus.group(1));
final Matcher mTram = P_NORMALIZE_LINE_TRAM.matcher(line); final Matcher mTram = P_NORMALIZE_LINE_TRAM.matcher(line);
if (mTram.matches()) if (mTram.matches())
return newLine('T' + mTram.group(1)); return newLine('T', mTram.group(1));
final Matcher m = P_NORMALIZE_LINE.matcher(line); final Matcher m = P_NORMALIZE_LINE.matcher(line);
if (m.matches()) if (m.matches())
@ -2689,7 +2688,7 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider
final char normalizedType = normalizeType(type); final char normalizedType = normalizeType(type);
if (normalizedType != 0) if (normalizedType != 0)
return newLine(normalizedType + type + number); return newLine(normalizedType, type + number);
throw new IllegalStateException("cannot normalize type '" + type + "' number '" + number + "' line '" + line + "'"); throw new IllegalStateException("cannot normalize type '" + type + "' number '" + number + "' line '" + line + "'");
} }
@ -2714,11 +2713,11 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider
if (type.length() == 0) if (type.length() == 0)
{ {
if (number.length() == 0) if (number.length() == 0)
return newLine("?"); return newLine('?', null);
if (P_NORMALIZE_LINE_NUMBER.matcher(number).matches()) if (P_NORMALIZE_LINE_NUMBER.matcher(number).matches())
return newLine("?" + number); return newLine('?', number);
if (P_LINE_RUSSIA.matcher(number).matches()) if (P_LINE_RUSSIA.matcher(number).matches())
return newLine('R' + number); return newLine('R', number);
} }
else else
{ {
@ -2729,17 +2728,17 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider
{ {
final Matcher mBus = P_NORMALIZE_LINE_BUS.matcher(number); final Matcher mBus = P_NORMALIZE_LINE_BUS.matcher(number);
if (mBus.matches()) if (mBus.matches())
return newLine('B' + mBus.group(1)); return newLine('B', mBus.group(1));
} }
if (normalizedType == 'T') if (normalizedType == 'T')
{ {
final Matcher mTram = P_NORMALIZE_LINE_TRAM.matcher(number); final Matcher mTram = P_NORMALIZE_LINE_TRAM.matcher(number);
if (mTram.matches()) if (mTram.matches())
return newLine('T' + mTram.group(1)); return newLine('T', mTram.group(1));
} }
return newLine(normalizedType + number.replaceAll("\\s+", "")); return newLine(normalizedType, number.replaceAll("\\s+", ""));
} }
} }
@ -2749,8 +2748,10 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider
throw new IllegalStateException("cannot normalize line#type '" + lineAndType + "'"); throw new IllegalStateException("cannot normalize line#type '" + lineAndType + "'");
} }
protected final Line newLine(final String lineStr, final Line.Attr... attrs) protected final Line newLine(final char product, final String name, final Line.Attr... attrs)
{ {
final String lineStr = product + (name != null ? name : "?");
if (attrs.length == 0) if (attrs.length == 0)
{ {
return new Line(null, lineStr, lineStyle(lineStr)); return new Line(null, lineStr, lineStyle(lineStr));

View file

@ -235,16 +235,16 @@ public final class BahnProvider extends AbstractHafasProvider
protected final Line parseLineWithoutType(final String line) protected final Line parseLineWithoutType(final String line)
{ {
if ("Schw-B".equals(line)) // Schwebebahn, gilt als "Straßenbahn besonderer Bauart" if ("Schw-B".equals(line)) // Schwebebahn, gilt als "Straßenbahn besonderer Bauart"
return newLine('T' + line); return newLine('T', line);
if (P_LINE_RUSSIA.matcher(line).matches()) if (P_LINE_RUSSIA.matcher(line).matches())
return newLine('R' + line); return newLine('R', line);
if (P_LINE_NUMBER.matcher(line).matches()) if (P_LINE_NUMBER.matcher(line).matches())
return newLine('?' + line); return newLine('?', line);
if ("---".equals(line)) if ("---".equals(line))
return newLine('?' + line); return newLine('?', line);
return super.parseLineWithoutType(line); return super.parseLineWithoutType(line);
} }

View file

@ -519,39 +519,39 @@ public final class BvgProvider extends AbstractHafasProvider
protected Line parseLineWithoutType(final String line) protected Line parseLineWithoutType(final String line)
{ {
if ("S41".equals(line)) if ("S41".equals(line))
return newLine("SS41", Attr.CIRCLE_CLOCKWISE); return newLine('S', "S41", Attr.CIRCLE_CLOCKWISE);
if ("S42".equals(line)) if ("S42".equals(line))
return newLine("SS42", Attr.CIRCLE_ANTICLOCKWISE); return newLine('S', "S42", Attr.CIRCLE_ANTICLOCKWISE);
if ("Bus S41".equals(line)) if ("Bus S41".equals(line))
return newLine("BS41", Attr.SERVICE_REPLACEMENT, Attr.CIRCLE_CLOCKWISE); return newLine('B', "S41", Attr.SERVICE_REPLACEMENT, Attr.CIRCLE_CLOCKWISE);
if ("Bus S42".equals(line)) if ("Bus S42".equals(line))
return newLine("BS42", Attr.SERVICE_REPLACEMENT, Attr.CIRCLE_ANTICLOCKWISE); return newLine('B', "S42", Attr.SERVICE_REPLACEMENT, Attr.CIRCLE_ANTICLOCKWISE);
if ("Bus TXL".equals(line)) if ("Bus TXL".equals(line))
return newLine("BTXL", Attr.LINE_AIRPORT); return newLine('B', "TXL", Attr.LINE_AIRPORT);
if ("S9".equals(line)) if ("S9".equals(line))
return newLine("SS9", Attr.LINE_AIRPORT); return newLine('S', "S9", Attr.LINE_AIRPORT);
if ("S45".equals(line)) if ("S45".equals(line))
return newLine("SS45", Attr.LINE_AIRPORT); return newLine('S', "S45", Attr.LINE_AIRPORT);
final Matcher mRegional = P_LINE_REGIONAL.matcher(line); final Matcher mRegional = P_LINE_REGIONAL.matcher(line);
if (mRegional.matches()) if (mRegional.matches())
return newLine('R' + mRegional.group(1)); return newLine('R', mRegional.group(1));
final Matcher mTram = P_LINE_TRAM.matcher(line); final Matcher mTram = P_LINE_TRAM.matcher(line);
if (mTram.matches()) if (mTram.matches())
return newLine('T' + mTram.group(1)); return newLine('T', mTram.group(1));
final Matcher mBus = P_LINE_BUS.matcher(line); final Matcher mBus = P_LINE_BUS.matcher(line);
if (mBus.matches()) if (mBus.matches())
return newLine('B' + mBus.group(1)); return newLine('B', mBus.group(1));
if (P_LINE_FERRY.matcher(line).matches()) if (P_LINE_FERRY.matcher(line).matches())
return newLine('F' + line); return newLine('F', line);
if (P_LINE_NUMBER.matcher(line).matches()) if (P_LINE_NUMBER.matcher(line).matches())
return newLine('R' + line); return newLine('R', line);
return super.parseLineWithoutType(line); return super.parseLineWithoutType(line);
} }

View file

@ -159,7 +159,7 @@ public class EireannProvider extends AbstractHafasProvider
{ {
final Matcher mLine = P_NORMALIZE_LINE.matcher(lineAndType); final Matcher mLine = P_NORMALIZE_LINE.matcher(lineAndType);
if (mLine.matches()) if (mLine.matches())
return newLine('B' + mLine.group(1)); return newLine('B', mLine.group(1));
return super.parseLineAndType(lineAndType); return super.parseLineAndType(lineAndType);
} }

View file

@ -205,10 +205,10 @@ public class PlProvider extends AbstractHafasProvider
{ {
final Matcher mRussia = P_NORMALIZE_LINE_RUSSIA.matcher(line); final Matcher mRussia = P_NORMALIZE_LINE_RUSSIA.matcher(line);
if (mRussia.matches()) if (mRussia.matches())
return newLine('R' + mRussia.group(1)); return newLine('R', mRussia.group(1));
if (P_NORMALIZE_LINE_NUMBER.matcher(line).matches()) if (P_NORMALIZE_LINE_NUMBER.matcher(line).matches())
return newLine('R' + line); return newLine('R', line);
return super.parseLineWithoutType(line); return super.parseLineWithoutType(line);
} }

View file

@ -310,9 +310,9 @@ public class RmvProvider extends AbstractHafasProvider
protected Line parseLineWithoutType(final String line) protected Line parseLineWithoutType(final String line)
{ {
if ("11".equals(line)) if ("11".equals(line))
return newLine("T11"); return newLine('T', "11");
if ("12".equals(line)) if ("12".equals(line))
return newLine("T12"); return newLine('T', "12");
return super.parseLineWithoutType(line); return super.parseLineWithoutType(line);
} }

View file

@ -207,12 +207,12 @@ public class SeProvider extends AbstractHafasProvider
{ {
final Matcher mBus = P_NORMALIZE_LINE_BUS.matcher(line); final Matcher mBus = P_NORMALIZE_LINE_BUS.matcher(line);
if (mBus.matches()) if (mBus.matches())
return newLine('B' + mBus.group(1)); return newLine('B', mBus.group(1));
final Matcher mSubway = P_NORMALIZE_LINE_SUBWAY.matcher(line); final Matcher mSubway = P_NORMALIZE_LINE_SUBWAY.matcher(line);
if (mSubway.matches()) if (mSubway.matches())
return newLine("UT" + mSubway.group(1)); return newLine('U', "T" + mSubway.group(1));
return newLine('?' + line); return newLine('?', line);
} }
} }

View file

@ -199,7 +199,7 @@ public class StockholmProvider extends AbstractHafasProvider
{ {
final char normalizedType = normalizeType(type); final char normalizedType = normalizeType(type);
if (normalizedType != 0) if (normalizedType != 0)
return newLine(normalizedType + number); return newLine(normalizedType, number);
} }
throw new IllegalStateException("cannot normalize type " + type + " number " + number + " line#type " + lineAndType); throw new IllegalStateException("cannot normalize type " + type + " number " + number + " line#type " + lineAndType);

View file

@ -200,17 +200,17 @@ public class ZvvProvider extends AbstractHafasProvider
final String type = m.group(2); final String type = m.group(2);
if ("Bus-NF".equals(type)) if ("Bus-NF".equals(type))
return newLine('B' + number, Line.Attr.WHEEL_CHAIR_ACCESS); return newLine('B', number, Line.Attr.WHEEL_CHAIR_ACCESS);
if ("Tro-NF".equals(type)) if ("Tro-NF".equals(type))
return newLine('B' + number, Line.Attr.WHEEL_CHAIR_ACCESS); return newLine('B', number, Line.Attr.WHEEL_CHAIR_ACCESS);
if ("Trm-NF".equals(type)) if ("Trm-NF".equals(type))
return newLine('T' + number, Line.Attr.WHEEL_CHAIR_ACCESS); return newLine('T', number, Line.Attr.WHEEL_CHAIR_ACCESS);
if (type.length() > 0) if (type.length() > 0)
{ {
final char normalizedType = normalizeType(type); final char normalizedType = normalizeType(type);
if (normalizedType != 0) if (normalizedType != 0)
return newLine(normalizedType + number); return newLine(normalizedType, number);
} }
throw new IllegalStateException("cannot normalize type " + type + " number " + number + " line#type " + lineAndType); throw new IllegalStateException("cannot normalize type " + type + " number " + number + " line#type " + lineAndType);