mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-15 17:10:30 +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 departureDateTime = ParserUtils.joinDateTime(departureDate, departureTime);
|
||||||
final Date arrivalDateTime = ParserUtils.joinDateTime(arrivalDate, arrivalTime);
|
final Date arrivalDateTime = ParserUtils.joinDateTime(arrivalDate, arrivalTime);
|
||||||
lastTrip = new Connection.Trip(line, LINES.get(line.charAt(0)), null, departureDateTime, departurePosition, 0, departure,
|
lastTrip = new Connection.Trip(line, line != null ? LINES.get(line.charAt(0)) : null, null, departureDateTime,
|
||||||
arrivalDateTime, arrivalPosition, 0, arrival);
|
departurePosition, 0, departure, arrivalDateTime, arrivalPosition, 0, arrival);
|
||||||
parts.add(lastTrip);
|
parts.add(lastTrip);
|
||||||
|
|
||||||
if (firstDepartureTime == null)
|
if (firstDepartureTime == null)
|
||||||
|
@ -465,10 +465,7 @@ public final class BahnProvider implements NetworkProvider
|
||||||
private static Departure parseDeparture(final Matcher mDep, final Date currentTime)
|
private static Departure parseDeparture(final Matcher mDep, final Date currentTime)
|
||||||
{
|
{
|
||||||
// line
|
// line
|
||||||
String line = normalizeLine(ParserUtils.resolveEntities(mDep.group(1)));
|
final 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;
|
|
||||||
|
|
||||||
// destination
|
// destination
|
||||||
final String destination = ParserUtils.resolveEntities(mDep.group(2));
|
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)
|
if (ParserUtils.timeDiff(parsed.getTime(), currentTime) < -PARSER_DAY_ROLLOVER_THRESHOLD_MS)
|
||||||
parsed.add(Calendar.DAY_OF_MONTH, 1);
|
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 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 EIC Polen?
|
||||||
// TODO EM East Midland? http://www.eastmidlandstrains.co.uk
|
// TODO EM East Midland? http://www.eastmidlandstrains.co.uk
|
||||||
|
|
||||||
if (line.length() == 0)
|
if (line == null || line.length() == 0)
|
||||||
return line;
|
return null;
|
||||||
|
|
||||||
final Matcher m = P_NORMALIZE_LINE.matcher(line);
|
final Matcher m = P_NORMALIZE_LINE.matcher(line);
|
||||||
if (m.matches())
|
if (m.matches())
|
||||||
|
@ -536,7 +533,7 @@ public final class BahnProvider implements NetworkProvider
|
||||||
return "IAVE" + number;
|
return "IAVE" + number;
|
||||||
if (type.equals("SC")) // SuperCity, cz
|
if (type.equals("SC")) // SuperCity, cz
|
||||||
return "ISC" + number;
|
return "ISC" + number;
|
||||||
if (type.equals("EST")) // Eurostar
|
if (type.equals("EST")) // Eurostar Frankreich
|
||||||
return "IEST" + number;
|
return "IEST" + number;
|
||||||
if (type.equals("ES")) // Eurostar Italia
|
if (type.equals("ES")) // Eurostar Italia
|
||||||
return "IES" + number;
|
return "IES" + number;
|
||||||
|
|
|
@ -351,8 +351,8 @@ public class RmvProvider implements NetworkProvider
|
||||||
|
|
||||||
final Date departureDateTime = ParserUtils.joinDateTime(currentDate, departureTime);
|
final Date departureDateTime = ParserUtils.joinDateTime(currentDate, departureTime);
|
||||||
final Date arrivalDateTime = ParserUtils.joinDateTime(currentDate, arrivalTime);
|
final Date arrivalDateTime = ParserUtils.joinDateTime(currentDate, arrivalTime);
|
||||||
lastTrip = new Connection.Trip(line, LINES.get(line.charAt(0)), destination, departureDateTime, departurePosition, 0,
|
lastTrip = new Connection.Trip(line, line != null ? LINES.get(line.charAt(0)) : null, destination, departureDateTime,
|
||||||
departure, arrivalDateTime, arrivalPosition, 0, arrival);
|
departurePosition, 0, departure, arrivalDateTime, arrivalPosition, 0, arrival);
|
||||||
parts.add(lastTrip);
|
parts.add(lastTrip);
|
||||||
|
|
||||||
if (firstDepartureTime == null)
|
if (firstDepartureTime == null)
|
||||||
|
@ -464,10 +464,7 @@ public class RmvProvider implements NetworkProvider
|
||||||
private static Departure parseDeparture(final Matcher mDep, final Date currentTime)
|
private static Departure parseDeparture(final Matcher mDep, final Date currentTime)
|
||||||
{
|
{
|
||||||
// line
|
// line
|
||||||
String line = normalizeLine(ParserUtils.resolveEntities(mDep.group(1)));
|
final 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;
|
|
||||||
|
|
||||||
// destination
|
// destination
|
||||||
final String destination = ParserUtils.resolveEntities(mDep.group(2));
|
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)
|
if (ParserUtils.timeDiff(parsed.getTime(), currentTime) < -PARSER_DAY_ROLLOVER_THRESHOLD_MS)
|
||||||
parsed.add(Calendar.DAY_OF_MONTH, 1);
|
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 final Pattern P_NORMALIZE_LINE = Pattern.compile("([A-Za-zÄÖÜäöüß]+)[\\s-]*(.*)");
|
||||||
|
|
||||||
private static String normalizeLine(final String line)
|
private static String normalizeLine(final String line)
|
||||||
{
|
{
|
||||||
if (line.length() == 0)
|
if (line == null || line.length() == 0)
|
||||||
return line;
|
return null;
|
||||||
|
|
||||||
final Matcher m = P_NORMALIZE_LINE.matcher(line);
|
final Matcher m = P_NORMALIZE_LINE.matcher(line);
|
||||||
if (m.matches())
|
if (m.matches())
|
||||||
|
|
|
@ -176,10 +176,7 @@ public class SbbProvider implements NetworkProvider
|
||||||
private static Departure parseDeparture(final Matcher mDep, final Date currentTime)
|
private static Departure parseDeparture(final Matcher mDep, final Date currentTime)
|
||||||
{
|
{
|
||||||
// line
|
// line
|
||||||
String line = normalizeLine(ParserUtils.resolveEntities(mDep.group(1)));
|
final 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;
|
|
||||||
|
|
||||||
// destination
|
// destination
|
||||||
final String destination = ParserUtils.resolveEntities(mDep.group(2));
|
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)
|
if (ParserUtils.timeDiff(parsed.getTime(), currentTime) < -PARSER_DAY_ROLLOVER_THRESHOLD_MS)
|
||||||
parsed.add(Calendar.DAY_OF_MONTH, 1);
|
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 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 IN Torino-Napoli
|
||||||
// TODO TAL
|
// TODO TAL
|
||||||
|
|
||||||
if (line.length() == 0)
|
if (line == null || line.length() == 0)
|
||||||
return line;
|
return null;
|
||||||
|
|
||||||
final Matcher m = P_NORMALIZE_LINE.matcher(line);
|
final Matcher m = P_NORMALIZE_LINE.matcher(line);
|
||||||
if (m.matches())
|
if (m.matches())
|
||||||
|
|
|
@ -217,11 +217,9 @@ public final class VbbProvider implements NetworkProvider
|
||||||
Date arrivalTime = ParserUtils.joinDateTime(currentDate, ParserUtils.parseTime(mConFine.group(3)));
|
Date arrivalTime = ParserUtils.joinDateTime(currentDate, ParserUtils.parseTime(mConFine.group(3)));
|
||||||
if (departureTime.after(arrivalTime))
|
if (departureTime.after(arrivalTime))
|
||||||
arrivalTime = ParserUtils.addDays(arrivalTime, 1);
|
arrivalTime = ParserUtils.addDays(arrivalTime, 1);
|
||||||
String line = mConFine.group(4);
|
final String line = normalizeLine(ParserUtils.resolveEntities(mConFine.group(4)));
|
||||||
if (line != null)
|
|
||||||
line = normalizeLine(ParserUtils.resolveEntities(line));
|
|
||||||
final Connection connection = new Connection(link, departureTime, arrivalTime, 0, from, 0, to, new ArrayList<Connection.Part>(1));
|
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);
|
connections.add(connection);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -321,8 +319,8 @@ public final class VbbProvider implements NetworkProvider
|
||||||
|
|
||||||
final String arrival = ParserUtils.resolveEntities(mDetFine.group(10));
|
final String arrival = ParserUtils.resolveEntities(mDetFine.group(10));
|
||||||
|
|
||||||
parts.add(new Connection.Trip(line, LINES.get(line), destination, departureTime, departurePosition, departureId, departure,
|
parts.add(new Connection.Trip(line, line != null ? LINES.get(line) : null, destination, departureTime, departurePosition,
|
||||||
arrivalTime, arrivalPosition, arrivalId, arrival));
|
departureId, departure, arrivalTime, arrivalPosition, arrivalId, arrival));
|
||||||
|
|
||||||
if (firstDepartureTime == null)
|
if (firstDepartureTime == null)
|
||||||
firstDepartureTime = departureTime;
|
firstDepartureTime = departureTime;
|
||||||
|
@ -473,7 +471,7 @@ public final class VbbProvider implements NetworkProvider
|
||||||
// destination
|
// destination
|
||||||
final String destination = ParserUtils.resolveEntities(mDep.group(3));
|
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)
|
private static final Date parseDate(String str)
|
||||||
|
@ -501,6 +499,9 @@ public final class VbbProvider implements NetworkProvider
|
||||||
|
|
||||||
private static String normalizeLine(final String line)
|
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")
|
if (line.startsWith("RE") || line.startsWith("RB") || line.startsWith("NE") || line.startsWith("OE") || line.startsWith("MR")
|
||||||
|| line.startsWith("PE"))
|
|| line.startsWith("PE"))
|
||||||
return "R" + line;
|
return "R" + line;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue