make more robust against empty lines

git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@30 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
andreas.schildbach 2010-07-27 12:32:26 +00:00
parent 304cae4c55
commit 703b916ba7
4 changed files with 25 additions and 33 deletions

View file

@ -176,10 +176,7 @@ public class SbbProvider implements NetworkProvider
private static Departure parseDeparture(final Matcher mDep, final Date currentTime)
{
// line
String line = normalizeLine(ParserUtils.resolveEntities(mDep.group(1)));
if (line.length() == 0)
line = null;
final int[] lineColors = line != null ? LINES.get(line.charAt(0)) : null;
final String line = normalizeLine(ParserUtils.resolveEntities(mDep.group(1)));
// destination
final String destination = ParserUtils.resolveEntities(mDep.group(2));
@ -195,7 +192,7 @@ public class SbbProvider implements NetworkProvider
if (ParserUtils.timeDiff(parsed.getTime(), currentTime) < -PARSER_DAY_ROLLOVER_THRESHOLD_MS)
parsed.add(Calendar.DAY_OF_MONTH, 1);
return new Departure(parsed.getTime(), line, lineColors, destination);
return new Departure(parsed.getTime(), line, line != null ? LINES.get(line.charAt(0)) : null, destination);
}
private static final Pattern P_NORMALIZE_LINE = Pattern.compile("([A-Za-zÄÖÜäöüß]+)[\\s-]*(.*)");
@ -205,8 +202,8 @@ public class SbbProvider implements NetworkProvider
// TODO IN Torino-Napoli
// TODO TAL
if (line.length() == 0)
return line;
if (line == null || line.length() == 0)
return null;
final Matcher m = P_NORMALIZE_LINE.matcher(line);
if (m.matches())