mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-19 00:39:58 +00:00
use common line parser for efa based apis
git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@213 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
parent
e8d2d60919
commit
8419822b30
4 changed files with 242 additions and 331 deletions
|
@ -123,7 +123,198 @@ public abstract class AbstractEfaProvider implements NetworkProvider
|
|||
return (double) value / 1000000;
|
||||
}
|
||||
|
||||
protected abstract String parseLine(String number, String symbol, String mot);
|
||||
private static final Pattern P_LINE_RE = Pattern.compile("RE\\d+");
|
||||
private static final Pattern P_LINE_RB = Pattern.compile("RB\\d+");
|
||||
private static final Pattern P_LINE_U = Pattern.compile("U\\d+");
|
||||
|
||||
protected String parseLine(final String number, final String symbol, final String mot)
|
||||
{
|
||||
if (!number.equals(symbol))
|
||||
throw new IllegalStateException("number " + number + ", symbol " + symbol);
|
||||
|
||||
final int t = Integer.parseInt(mot);
|
||||
|
||||
if (t == 0)
|
||||
{
|
||||
final String[] parts = number.split(" ", 3);
|
||||
final String type = parts[0];
|
||||
final String num = parts.length >= 2 ? parts[1] : null;
|
||||
final String str = type + (num != null ? num : "");
|
||||
|
||||
if (type.equals("EC")) // Eurocity
|
||||
return 'I' + str;
|
||||
if (type.equals("EN")) // Euronight
|
||||
return 'I' + str;
|
||||
if (type.equals("IC")) // Intercity
|
||||
return 'I' + str;
|
||||
if (type.equals("ICE")) // Intercity Express
|
||||
return 'I' + str;
|
||||
if (type.equals("CNL")) // City Night Line
|
||||
return 'I' + str;
|
||||
if (type.equals("THA")) // Thalys
|
||||
return 'I' + str;
|
||||
if (type.equals("TGV")) // TGV
|
||||
return 'I' + str;
|
||||
if (type.equals("RJ")) // railjet
|
||||
return 'I' + str;
|
||||
|
||||
if (type.equals("IR")) // Interregio
|
||||
return 'R' + str;
|
||||
if (type.equals("IRE")) // Interregio-Express
|
||||
return 'R' + str;
|
||||
if (type.equals("RE")) // Regional-Express
|
||||
return 'R' + str;
|
||||
if (P_LINE_RE.matcher(type).matches())
|
||||
return 'R' + str;
|
||||
if (type.equals("RB")) // Regionalbahn
|
||||
return 'R' + str;
|
||||
if (P_LINE_RB.matcher(type).matches())
|
||||
return 'R' + str;
|
||||
if (type.equals("R")) // Regionalzug
|
||||
return 'R' + str;
|
||||
if (type.equals("D")) // Schnellzug
|
||||
return 'R' + str;
|
||||
if (type.equals("WFB")) // Westfalenbahn
|
||||
return 'R' + str;
|
||||
if (type.equals("NWB")) // NordWestBahn
|
||||
return 'R' + str;
|
||||
if (type.equals("ME")) // Metronom
|
||||
return 'R' + str;
|
||||
if (type.equals("ERB")) // eurobahn
|
||||
return 'R' + str;
|
||||
if (type.equals("CAN")) // cantus
|
||||
return 'R' + str;
|
||||
if (type.equals("HEX")) // Veolia Verkehr Sachsen-Anhalt
|
||||
return 'R' + str;
|
||||
if (type.equals("EB")) // Erfurter Bahn
|
||||
return 'R' + str;
|
||||
if (type.equals("MRB")) // Mittelrheinbahn
|
||||
return 'R' + str;
|
||||
if (type.equals("ABR")) // ABELLIO Rail NRW
|
||||
return 'R' + str;
|
||||
if (type.equals("NEB")) // Niederbarnimer Eisenbahn
|
||||
return 'R' + str;
|
||||
if (type.equals("OE")) // Ostdeutsche Eisenbahn
|
||||
return 'R' + str;
|
||||
if (type.equals("MR")) // Märkische Regiobahn
|
||||
return 'R' + str;
|
||||
if (type.equals("OLA")) // Ostseeland Verkehr
|
||||
return 'R' + str;
|
||||
if (type.equals("UBB")) // Usedomer Bäderbahn
|
||||
return 'R' + str;
|
||||
if (type.equals("EVB")) // Elbe-Weser
|
||||
return 'R' + str;
|
||||
if (type.equals("PEG")) // Prignitzer Eisenbahngesellschaft
|
||||
return 'R' + str;
|
||||
if (type.equals("RTB")) // Rurtalbahn
|
||||
return 'R' + str;
|
||||
if (type.equals("STB")) // Süd-Thüringen-Bahn
|
||||
return 'R' + str;
|
||||
if (type.equals("HTB")) // Hellertalbahn
|
||||
return 'R' + str;
|
||||
if (type.equals("VBG")) // Vogtlandbahn
|
||||
return 'R' + str;
|
||||
if (type.equals("VX")) // Vogtland Express
|
||||
return 'R' + str;
|
||||
if (type.equals("CB")) // City-Bahn Chemnitz
|
||||
return 'R' + str;
|
||||
if (type.equals("VEC")) // VECTUS Verkehrsgesellschaft
|
||||
return 'R' + str;
|
||||
if (type.equals("HzL")) // Hohenzollerische Landesbahn
|
||||
return 'R' + str;
|
||||
if (type.equals("OSB")) // Ortenau-S-Bahn
|
||||
return 'R' + str;
|
||||
if (type.equals("SBB")) // SBB
|
||||
return 'R' + str;
|
||||
if (type.equals("MBB")) // Mecklenburgische Bäderbahn Molli
|
||||
return 'R' + str;
|
||||
if (type.equals("OS")) // Regionalbahn
|
||||
return 'R' + str;
|
||||
if (type.equals("SP"))
|
||||
return 'R' + str;
|
||||
if (type.equals("Dab")) // Daadetalbahn
|
||||
return 'R' + str;
|
||||
if (type.equals("FEG")) // Freiberger Eisenbahngesellschaft
|
||||
return 'R' + str;
|
||||
if (type.equals("ARR")) // ARRIVA
|
||||
return 'R' + str;
|
||||
if (type.equals("HSB")) // Harzer Schmalspurbahn
|
||||
return 'R' + str;
|
||||
if (type.equals("SBE")) // Sächsisch-Böhmische Eisenbahngesellschaft
|
||||
return 'R' + str;
|
||||
if (type.equals("ALX")) // Arriva-Länderbahn-Express
|
||||
return 'R' + str;
|
||||
if (type.equals("MEr")) // metronom regional
|
||||
return 'R' + str;
|
||||
if (type.equals("AKN")) // AKN Eisenbahn
|
||||
return 'R' + str;
|
||||
if (type.equals("ZUG")) // Regionalbahn
|
||||
return 'R' + str;
|
||||
if (type.equals("SOE")) // Sächsisch-Oberlausitzer Eisenbahngesellschaft
|
||||
return 'R' + str;
|
||||
if (type.equals("VIA")) // VIAS
|
||||
return 'R' + str;
|
||||
if (type.equals("BRB")) // Bayerische Regiobahn
|
||||
return 'R' + str;
|
||||
if (type.equals("BLB")) // Berchtesgadener Land Bahn
|
||||
return 'R' + str;
|
||||
if (type.equals("HLB")) // Hessische Landesbahn
|
||||
return 'R' + str;
|
||||
if (type.equals("NOB")) // NordOstseeBahn
|
||||
return 'R' + str;
|
||||
if (type.equals("WEG")) // Wieslauftalbahn
|
||||
return 'R' + str;
|
||||
if (type.equals("NBE")) // Nordbahn Eisenbahngesellschaft
|
||||
return 'R' + str;
|
||||
if (type.equals("VEN")) // Rhenus Veniro
|
||||
return 'R' + str;
|
||||
if (type.equals("DPN")) // Nahreisezug
|
||||
return 'R' + str;
|
||||
if (type.equals("SHB")) // Schleswig-Holstein-Bahn
|
||||
return 'R' + str;
|
||||
if (type.equals("RBG")) // Regental Bahnbetriebs GmbH
|
||||
return 'R' + str;
|
||||
if (type.equals("BOB")) // Bayerische Oberlandbahn
|
||||
return 'R' + str;
|
||||
if (type.equals("SWE")) // Südwestdeutsche Verkehrs AG
|
||||
return 'R' + str;
|
||||
if (type.equals("VE")) // Vetter
|
||||
return 'R' + str;
|
||||
if (type.equals("SDG")) // Sächsische Dampfeisenbahngesellschaft
|
||||
return 'R' + str;
|
||||
if (type.equals("PRE")) // Pressnitztalbahn
|
||||
return 'R' + str;
|
||||
|
||||
if (type.equals("BSB")) // Breisgau-S-Bahn
|
||||
return 'S' + str;
|
||||
|
||||
if (P_LINE_U.matcher(type).matches())
|
||||
return 'U' + str;
|
||||
|
||||
if (type.equals("RT")) // RegioTram
|
||||
return 'T' + str;
|
||||
if (type.equals("STR")) // Nordhausen
|
||||
return 'T' + str;
|
||||
|
||||
throw new IllegalArgumentException("cannot normalize: " + number);
|
||||
}
|
||||
if (t == 1)
|
||||
return 'S' + number;
|
||||
if (t == 2)
|
||||
return 'U' + number;
|
||||
if (t == 3 || t == 4)
|
||||
return 'T' + number;
|
||||
if (t == 5 || t == 6 || t == 7 || t == 10)
|
||||
return 'B' + number;
|
||||
if (t == 8)
|
||||
return 'C' + number;
|
||||
if (t == 9)
|
||||
return 'F' + number;
|
||||
if (t == 11)
|
||||
return '?' + number;
|
||||
|
||||
throw new IllegalStateException("cannot normalize mot '" + mot + "' number '" + number + "'");
|
||||
}
|
||||
|
||||
public QueryDeparturesResult queryDepartures(final String uri) throws IOException
|
||||
{
|
||||
|
@ -142,7 +333,7 @@ public abstract class AbstractEfaProvider implements NetworkProvider
|
|||
XmlPullUtil.jumpToStartTag(pp, null, "odvNameElem");
|
||||
final int locationId = Integer.parseInt(pp.getAttributeValue(null, "stopID"));
|
||||
|
||||
final String location = pp.nextText();
|
||||
final String location = normalizeLocationName(pp.nextText());
|
||||
|
||||
final Calendar departureTime = new GregorianCalendar();
|
||||
final List<Departure> departures = new ArrayList<Departure>(8);
|
||||
|
@ -178,7 +369,7 @@ public abstract class AbstractEfaProvider implements NetworkProvider
|
|||
final String line = parseLine(pp.getAttributeValue(null, "number"), pp.getAttributeValue(null, "symbol"), pp
|
||||
.getAttributeValue(null, "motType"));
|
||||
final boolean isRealtime = pp.getAttributeValue(null, "realtime").equals("1");
|
||||
final String destination = pp.getAttributeValue(null, "direction");
|
||||
final String destination = normalizeLocationName(pp.getAttributeValue(null, "direction"));
|
||||
final int destinationId = Integer.parseInt(pp.getAttributeValue(null, "destID"));
|
||||
XmlPullUtil.skipRestOfTree(pp);
|
||||
|
||||
|
@ -220,4 +411,11 @@ public abstract class AbstractEfaProvider implements NetworkProvider
|
|||
calendar.set(Calendar.HOUR, Integer.parseInt(pp.getAttributeValue(null, "hour")));
|
||||
calendar.set(Calendar.MINUTE, Integer.parseInt(pp.getAttributeValue(null, "minute")));
|
||||
}
|
||||
|
||||
private static final Pattern P_STATION_NAME_WHITESPACE = Pattern.compile("\\s+");
|
||||
|
||||
private static String normalizeLocationName(final String name)
|
||||
{
|
||||
return P_STATION_NAME_WHITESPACE.matcher(name).replaceAll(" ");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue