mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-15 00:50:31 +00:00
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:
parent
304cae4c55
commit
703b916ba7
4 changed files with 25 additions and 33 deletions
|
@ -352,8 +352,8 @@ public final class BahnProvider implements NetworkProvider
|
|||
|
||||
final Date departureDateTime = ParserUtils.joinDateTime(departureDate, departureTime);
|
||||
final Date arrivalDateTime = ParserUtils.joinDateTime(arrivalDate, arrivalTime);
|
||||
lastTrip = new Connection.Trip(line, LINES.get(line.charAt(0)), null, departureDateTime, departurePosition, 0, departure,
|
||||
arrivalDateTime, arrivalPosition, 0, arrival);
|
||||
lastTrip = new Connection.Trip(line, line != null ? LINES.get(line.charAt(0)) : null, null, departureDateTime,
|
||||
departurePosition, 0, departure, arrivalDateTime, arrivalPosition, 0, arrival);
|
||||
parts.add(lastTrip);
|
||||
|
||||
if (firstDepartureTime == null)
|
||||
|
@ -465,10 +465,7 @@ public final class BahnProvider 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));
|
||||
|
@ -484,7 +481,7 @@ public final class BahnProvider 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-]*(.*)");
|
||||
|
@ -497,8 +494,8 @@ public final class BahnProvider implements NetworkProvider
|
|||
// TODO EIC Polen?
|
||||
// TODO EM East Midland? http://www.eastmidlandstrains.co.uk
|
||||
|
||||
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())
|
||||
|
@ -536,7 +533,7 @@ public final class BahnProvider implements NetworkProvider
|
|||
return "IAVE" + number;
|
||||
if (type.equals("SC")) // SuperCity, cz
|
||||
return "ISC" + number;
|
||||
if (type.equals("EST")) // Eurostar
|
||||
if (type.equals("EST")) // Eurostar Frankreich
|
||||
return "IEST" + number;
|
||||
if (type.equals("ES")) // Eurostar Italia
|
||||
return "IES" + number;
|
||||
|
|
|
@ -351,8 +351,8 @@ public class RmvProvider implements NetworkProvider
|
|||
|
||||
final Date departureDateTime = ParserUtils.joinDateTime(currentDate, departureTime);
|
||||
final Date arrivalDateTime = ParserUtils.joinDateTime(currentDate, arrivalTime);
|
||||
lastTrip = new Connection.Trip(line, LINES.get(line.charAt(0)), destination, departureDateTime, departurePosition, 0,
|
||||
departure, arrivalDateTime, arrivalPosition, 0, arrival);
|
||||
lastTrip = new Connection.Trip(line, line != null ? LINES.get(line.charAt(0)) : null, destination, departureDateTime,
|
||||
departurePosition, 0, departure, arrivalDateTime, arrivalPosition, 0, arrival);
|
||||
parts.add(lastTrip);
|
||||
|
||||
if (firstDepartureTime == null)
|
||||
|
@ -464,10 +464,7 @@ public class RmvProvider 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));
|
||||
|
@ -483,15 +480,15 @@ public class RmvProvider 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-]*(.*)");
|
||||
|
||||
private static String normalizeLine(final String line)
|
||||
{
|
||||
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())
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -217,11 +217,9 @@ public final class VbbProvider implements NetworkProvider
|
|||
Date arrivalTime = ParserUtils.joinDateTime(currentDate, ParserUtils.parseTime(mConFine.group(3)));
|
||||
if (departureTime.after(arrivalTime))
|
||||
arrivalTime = ParserUtils.addDays(arrivalTime, 1);
|
||||
String line = mConFine.group(4);
|
||||
if (line != null)
|
||||
line = normalizeLine(ParserUtils.resolveEntities(line));
|
||||
final String line = normalizeLine(ParserUtils.resolveEntities(mConFine.group(4)));
|
||||
final Connection connection = new Connection(link, departureTime, arrivalTime, 0, from, 0, to, new ArrayList<Connection.Part>(1));
|
||||
connection.parts.add(new Connection.Trip(departureTime, arrivalTime, line, LINES.get(line)));
|
||||
connection.parts.add(new Connection.Trip(departureTime, arrivalTime, line, line != null ? LINES.get(line) : null));
|
||||
connections.add(connection);
|
||||
}
|
||||
else
|
||||
|
@ -321,8 +319,8 @@ public final class VbbProvider implements NetworkProvider
|
|||
|
||||
final String arrival = ParserUtils.resolveEntities(mDetFine.group(10));
|
||||
|
||||
parts.add(new Connection.Trip(line, LINES.get(line), destination, departureTime, departurePosition, departureId, departure,
|
||||
arrivalTime, arrivalPosition, arrivalId, arrival));
|
||||
parts.add(new Connection.Trip(line, line != null ? LINES.get(line) : null, destination, departureTime, departurePosition,
|
||||
departureId, departure, arrivalTime, arrivalPosition, arrivalId, arrival));
|
||||
|
||||
if (firstDepartureTime == null)
|
||||
firstDepartureTime = departureTime;
|
||||
|
@ -473,7 +471,7 @@ public final class VbbProvider implements NetworkProvider
|
|||
// destination
|
||||
final String destination = ParserUtils.resolveEntities(mDep.group(3));
|
||||
|
||||
return new Departure(parsed.getTime(), line, LINES.get(line), destination);
|
||||
return new Departure(parsed.getTime(), line, line != null ? LINES.get(line) : null, destination);
|
||||
}
|
||||
|
||||
private static final Date parseDate(String str)
|
||||
|
@ -501,6 +499,9 @@ public final class VbbProvider implements NetworkProvider
|
|||
|
||||
private static String normalizeLine(final String line)
|
||||
{
|
||||
if (line == null || line.length() == 0)
|
||||
return null;
|
||||
|
||||
if (line.startsWith("RE") || line.startsWith("RB") || line.startsWith("NE") || line.startsWith("OE") || line.startsWith("MR")
|
||||
|| line.startsWith("PE"))
|
||||
return "R" + line;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue