wheelchair access in Zurich

git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@811 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
andreas.schildbach@gmail.com 2011-10-06 14:01:38 +00:00
parent b7ab26c57c
commit 4eebf50007
2 changed files with 46 additions and 4 deletions

View file

@ -26,10 +26,12 @@ import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.TimeZone; import java.util.TimeZone;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -1757,17 +1759,27 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider
throw new IllegalStateException("cannot normalize line " + line); throw new IllegalStateException("cannot normalize line " + line);
} }
protected final Line newLine(final String lineStr) protected final Line newLine(final String lineStr, final Line.Attr... attrs)
{ {
return new Line(null, lineStr, lineColors(lineStr)); if (attrs.length == 0)
{
return new Line(null, lineStr, lineColors(lineStr));
}
else
{
final Set<Line.Attr> attrSet = new HashSet<Line.Attr>();
for (final Line.Attr attr : attrs)
attrSet.add(attr);
return new Line(null, lineStr, lineColors(lineStr), attrSet);
}
} }
private static final Pattern P_NORMALIZE_LINE_AND_TYPE = Pattern.compile("([^#]*)#(.*)"); protected static final Pattern P_NORMALIZE_LINE_AND_TYPE = Pattern.compile("([^#]*)#(.*)");
private static final Pattern P_NORMALIZE_LINE_NUMBER = Pattern.compile("\\d{2,5}"); private static final Pattern P_NORMALIZE_LINE_NUMBER = Pattern.compile("\\d{2,5}");
// saved from RtProvider // saved from RtProvider
private static final Pattern P_NORMALIZE_LINE_RUSSIA = Pattern.compile("(\\d{3}(BJ|FJ|IJ|MJ|NJ|OJ|TJ|SZ))"); private static final Pattern P_NORMALIZE_LINE_RUSSIA = Pattern.compile("(\\d{3}(BJ|FJ|IJ|MJ|NJ|OJ|TJ|SZ))");
protected final Line parseLineAndType(final String lineAndType) protected Line parseLineAndType(final String lineAndType)
{ {
final Matcher m = P_NORMALIZE_LINE_AND_TYPE.matcher(lineAndType); final Matcher m = P_NORMALIZE_LINE_AND_TYPE.matcher(lineAndType);
if (m.matches()) if (m.matches())

View file

@ -19,6 +19,7 @@ package de.schildbach.pte;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.regex.Matcher;
import de.schildbach.pte.dto.Line; import de.schildbach.pte.dto.Line;
import de.schildbach.pte.dto.Location; import de.schildbach.pte.dto.Location;
@ -168,6 +169,35 @@ public class ZvvProvider extends AbstractHafasProvider
return parseLineAndType(line); return parseLineAndType(line);
} }
@Override
protected Line parseLineAndType(final String lineAndType)
{
final Matcher m = P_NORMALIZE_LINE_AND_TYPE.matcher(lineAndType);
if (m.matches())
{
final String number = m.group(1).replaceAll("\\s+", " ");
final String type = m.group(2);
if ("Bus-NF".equals(type))
return newLine('B' + number, Line.Attr.WHEEL_CHAIR_ACCESS);
if ("Tro-NF".equals(type))
return newLine('B' + number, Line.Attr.WHEEL_CHAIR_ACCESS);
if ("Trm-NF".equals(type))
return newLine('T' + number, Line.Attr.WHEEL_CHAIR_ACCESS);
if (type.length() > 0)
{
final char normalizedType = normalizeType(type);
if (normalizedType != 0)
return newLine(normalizedType + number);
}
throw new IllegalStateException("cannot normalize type " + type + " number " + number + " line#type " + lineAndType);
}
throw new IllegalStateException("cannot normalize line#type " + lineAndType);
}
@Override @Override
protected char normalizeType(final String type) protected char normalizeType(final String type)
{ {