diff --git a/src/de/schildbach/pte/BahnProvider.java b/src/de/schildbach/pte/BahnProvider.java index 951aa0d4..0e55db6e 100644 --- a/src/de/schildbach/pte/BahnProvider.java +++ b/src/de/schildbach/pte/BahnProvider.java @@ -171,7 +171,7 @@ public final class BahnProvider implements NetworkProvider .compile("(zu dicht beieinander|mehrfach vorhanden oder identisch)|(leider konnte zu Ihrer Anfrage keine Verbindung gefunden werden)"); public QueryConnectionsResult queryConnections(final LocationType fromType, final String from, final LocationType viaType, final String via, - final LocationType toType, final String to, final Date date, final boolean dep) throws IOException + final LocationType toType, final String to, final Date date, final boolean dep, final WalkSpeed walkSpeed) throws IOException { final String uri = connectionsQueryUri(fromType, from, viaType, via, toType, to, date, dep); final CharSequence page = ParserUtils.scrape(uri); diff --git a/src/de/schildbach/pte/MvvProvider.java b/src/de/schildbach/pte/MvvProvider.java index 058b1bf8..aef0d55b 100644 --- a/src/de/schildbach/pte/MvvProvider.java +++ b/src/de/schildbach/pte/MvvProvider.java @@ -154,8 +154,16 @@ public class MvvProvider implements NetworkProvider } + private static final Map WALKSPEED_MAP = new HashMap(); + static + { + WALKSPEED_MAP.put(WalkSpeed.SLOW, "slow"); + WALKSPEED_MAP.put(WalkSpeed.NORMAL, "normal"); + WALKSPEED_MAP.put(WalkSpeed.FAST, "fast"); + } + private String connectionsQueryUri(final LocationType fromType, final String from, final LocationType viaType, final String via, - final LocationType toType, final String to, final Date date, final boolean dep) + final LocationType toType, final String to, final Date date, final boolean dep, final WalkSpeed walkSpeed) { final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyyMMdd"); final DateFormat YEAR_FORMAT = new SimpleDateFormat("yyyy"); @@ -270,6 +278,7 @@ public class MvvProvider implements NetworkProvider uri.append("&itdTimeHour=").append(ParserUtils.urlEncode(HOUR_FORMAT.format(date))); uri.append("&itdTimeMinute=").append(ParserUtils.urlEncode(MINUTE_FORMAT.format(date))); uri.append("&itdDate=").append(ParserUtils.urlEncode(DATE_FORMAT.format(date))); + uri.append("&changeSpeed=").append(WALKSPEED_MAP.get(walkSpeed)); return uri.toString(); } @@ -305,9 +314,9 @@ public class MvvProvider implements NetworkProvider "(Start und Ziel sind identisch)|(konnte keine Verbindung gefunden werden)", Pattern.CASE_INSENSITIVE); public QueryConnectionsResult queryConnections(final LocationType fromType, final String from, final LocationType viaType, final String via, - final LocationType toType, final String to, final Date date, final boolean dep) throws IOException + final LocationType toType, final String to, final Date date, final boolean dep, final WalkSpeed walkSpeed) throws IOException { - final String uri = connectionsQueryUri(fromType, from, viaType, via, toType, to, date, dep); + final String uri = connectionsQueryUri(fromType, from, viaType, via, toType, to, date, dep, walkSpeed); final CharSequence page = ParserUtils.scrape(uri); final Matcher mError = P_CHECK_CONNECTIONS_ERROR.matcher(page); diff --git a/src/de/schildbach/pte/NetworkProvider.java b/src/de/schildbach/pte/NetworkProvider.java index e434d0b5..d4f23552 100644 --- a/src/de/schildbach/pte/NetworkProvider.java +++ b/src/de/schildbach/pte/NetworkProvider.java @@ -38,6 +38,11 @@ public interface NetworkProvider ANY, STATION, WGS84, ADDRESS } + public enum WalkSpeed + { + SLOW, NORMAL, FAST + } + boolean hasCapabilities(Capability... capabilities); /** @@ -95,11 +100,13 @@ public interface NetworkProvider * desired date for departing, mandatory * @param dep * date is departure date? {@code true} for departure, {@code false} for arrival + * @param walkSpeed + * how fast can you walk? * @return result object that can contain alternatives to clear up ambiguousnesses, or contains possible connections * @throws IOException */ QueryConnectionsResult queryConnections(LocationType fromType, String from, LocationType viaType, String via, LocationType toType, String to, - Date date, boolean dep) throws IOException; + Date date, boolean dep, WalkSpeed walkSpeed) throws IOException; /** * Query more connections (e.g. earlier or later) diff --git a/src/de/schildbach/pte/OebbProvider.java b/src/de/schildbach/pte/OebbProvider.java index d7f74539..e8a5139b 100644 --- a/src/de/schildbach/pte/OebbProvider.java +++ b/src/de/schildbach/pte/OebbProvider.java @@ -66,8 +66,16 @@ public class OebbProvider implements NetworkProvider throw new UnsupportedOperationException(); } + private static final Map WALKSPEED_MAP = new HashMap(); + static + { + WALKSPEED_MAP.put(WalkSpeed.SLOW, "115"); + WALKSPEED_MAP.put(WalkSpeed.NORMAL, "100"); + WALKSPEED_MAP.put(WalkSpeed.FAST, "85"); + } + private String connectionsQueryUri(final LocationType fromType, final String from, final LocationType viaType, final String via, - final LocationType toType, final String to, final Date date, final boolean dep) + final LocationType toType, final String to, final Date date, final boolean dep, final WalkSpeed walkSpeed) { final DateFormat DATE_FORMAT = new SimpleDateFormat("dd.MM.yy"); final DateFormat TIME_FORMAT = new SimpleDateFormat("HH:mm"); @@ -90,6 +98,7 @@ public class OebbProvider implements NetworkProvider uri.append("&REQ0JourneyStopsZ0ID="); uri.append("&REQ0JourneyTime=").append(ParserUtils.urlEncode(TIME_FORMAT.format(date))); uri.append("&REQ0JourneyProduct_list=0:1111111111010000-000000"); + uri.append("&REQ0JourneyDep_Foot_speed=").append(WALKSPEED_MAP.get(walkSpeed)); uri.append("&existHafasAttrInc=yes"); uri.append("&existHafasDemo3=yes"); uri.append("&queryPageDisplayed=yes"); @@ -115,9 +124,9 @@ public class OebbProvider implements NetworkProvider private static final Pattern P_CHECK_CONNECTIONS_ERROR = Pattern.compile("(keine Verbindung gefunden werden)"); public QueryConnectionsResult queryConnections(final LocationType fromType, final String from, final LocationType viaType, final String via, - final LocationType toType, final String to, final Date date, final boolean dep) throws IOException + final LocationType toType, final String to, final Date date, final boolean dep, final WalkSpeed walkSpeed) throws IOException { - final String uri = connectionsQueryUri(fromType, from, viaType, via, toType, to, date, dep); + final String uri = connectionsQueryUri(fromType, from, viaType, via, toType, to, date, dep, walkSpeed); final CharSequence page = ParserUtils.scrape(uri); final Matcher mError = P_CHECK_CONNECTIONS_ERROR.matcher(page); diff --git a/src/de/schildbach/pte/RmvProvider.java b/src/de/schildbach/pte/RmvProvider.java index cd38c5c2..813775b0 100644 --- a/src/de/schildbach/pte/RmvProvider.java +++ b/src/de/schildbach/pte/RmvProvider.java @@ -135,8 +135,16 @@ public class RmvProvider implements NetworkProvider return (double) value / 1000000; } + private static final Map WALKSPEED_MAP = new HashMap(); + static + { + WALKSPEED_MAP.put(WalkSpeed.SLOW, "115"); + WALKSPEED_MAP.put(WalkSpeed.NORMAL, "100"); + WALKSPEED_MAP.put(WalkSpeed.FAST, "85"); + } + private String connectionsQueryUri(final LocationType fromType, final String from, final LocationType viaType, final String via, - final LocationType toType, final String to, final Date date, final boolean dep) + final LocationType toType, final String to, final Date date, final boolean dep, final WalkSpeed walkSpeed) { final DateFormat DATE_FORMAT = new SimpleDateFormat("dd.MM.yy"); final DateFormat TIME_FORMAT = new SimpleDateFormat("HH:mm"); @@ -156,6 +164,7 @@ public class RmvProvider implements NetworkProvider uri.append("&REQ0JourneyStops1.0G=").append(ParserUtils.urlEncode(via)); uri.append("&REQ0JourneyStops1.0A=").append(locationType(viaType)); } + uri.append("&REQ0JourneyDep_Foot_speed=").append(WALKSPEED_MAP.get(walkSpeed)); uri.append("&start=Suchen"); return uri.toString(); @@ -180,9 +189,9 @@ public class RmvProvider implements NetworkProvider "(?:(mehrfach vorhanden oder identisch)|(keine Verbindung gefunden werden))", Pattern.CASE_INSENSITIVE); public QueryConnectionsResult queryConnections(final LocationType fromType, final String from, final LocationType viaType, final String via, - final LocationType toType, final String to, final Date date, final boolean dep) throws IOException + final LocationType toType, final String to, final Date date, final boolean dep, final WalkSpeed walkSpeed) throws IOException { - final String uri = connectionsQueryUri(fromType, from, viaType, via, toType, to, date, dep); + final String uri = connectionsQueryUri(fromType, from, viaType, via, toType, to, date, dep, walkSpeed); final CharSequence page = ParserUtils.scrape(uri); final Matcher mError = P_CHECK_CONNECTIONS_ERROR.matcher(page); diff --git a/src/de/schildbach/pte/SbbProvider.java b/src/de/schildbach/pte/SbbProvider.java index 09833dbd..0f99a291 100644 --- a/src/de/schildbach/pte/SbbProvider.java +++ b/src/de/schildbach/pte/SbbProvider.java @@ -140,7 +140,7 @@ public class SbbProvider implements NetworkProvider .compile("(mehrfach vorhanden oder identisch)|(keine Verbindung gefunden werden)"); public QueryConnectionsResult queryConnections(final LocationType fromType, final String from, final LocationType viaType, final String via, - final LocationType toType, final String to, final Date date, final boolean dep) throws IOException + final LocationType toType, final String to, final Date date, final boolean dep, final WalkSpeed walkSpeed) throws IOException { final String uri = connectionsQueryUri(fromType, from, viaType, via, toType, to, date, dep); final CharSequence page = ParserUtils.scrape(uri); diff --git a/src/de/schildbach/pte/SncbProvider.java b/src/de/schildbach/pte/SncbProvider.java index 8247bdc3..0219dc60 100644 --- a/src/de/schildbach/pte/SncbProvider.java +++ b/src/de/schildbach/pte/SncbProvider.java @@ -38,7 +38,7 @@ public class SncbProvider implements NetworkProvider } public QueryConnectionsResult queryConnections(final LocationType fromType, final String from, final LocationType viaType, final String via, - final LocationType toType, final String to, final Date date, final boolean dep) throws IOException + final LocationType toType, final String to, final Date date, final boolean dep, final WalkSpeed walkSpeed) throws IOException { throw new UnsupportedOperationException(); } diff --git a/src/de/schildbach/pte/TflProvider.java b/src/de/schildbach/pte/TflProvider.java index 2fab972f..e86d99e4 100644 --- a/src/de/schildbach/pte/TflProvider.java +++ b/src/de/schildbach/pte/TflProvider.java @@ -56,7 +56,7 @@ public class TflProvider implements NetworkProvider } public QueryConnectionsResult queryConnections(final LocationType fromType, final String from, final LocationType viaType, final String via, - final LocationType toType, final String to, final Date date, final boolean dep) throws IOException + final LocationType toType, final String to, final Date date, final boolean dep, final WalkSpeed walkSpeed) throws IOException { throw new UnsupportedOperationException(); } diff --git a/src/de/schildbach/pte/VbbProvider.java b/src/de/schildbach/pte/VbbProvider.java index 3588a737..075f3583 100644 --- a/src/de/schildbach/pte/VbbProvider.java +++ b/src/de/schildbach/pte/VbbProvider.java @@ -244,7 +244,7 @@ public final class VbbProvider implements NetworkProvider .compile("(zu dicht beieinander|mehrfach vorhanden oder identisch)|(keine Verbindung gefunden)"); public QueryConnectionsResult queryConnections(final LocationType fromType, final String from, final LocationType viaType, final String via, - final LocationType toType, final String to, final Date date, final boolean dep) throws IOException + final LocationType toType, final String to, final Date date, final boolean dep, final WalkSpeed walkSpeed) throws IOException { final String uri = connectionsQueryUri(fromType, from, viaType, via, toType, to, date, dep); final CharSequence page = ParserUtils.scrape(uri); diff --git a/test/de/schildbach/pte/live/MvvProviderLiveTest.java b/test/de/schildbach/pte/live/MvvProviderLiveTest.java index 132cc1d1..d43f18e6 100644 --- a/test/de/schildbach/pte/live/MvvProviderLiveTest.java +++ b/test/de/schildbach/pte/live/MvvProviderLiveTest.java @@ -24,6 +24,7 @@ import org.junit.Test; import de.schildbach.pte.MvvProvider; import de.schildbach.pte.QueryConnectionsResult; import de.schildbach.pte.NetworkProvider.LocationType; +import de.schildbach.pte.NetworkProvider.WalkSpeed; /** * @author Andreas Schildbach @@ -36,7 +37,7 @@ public class MvvProviderLiveTest public void shortConnection() throws Exception { final QueryConnectionsResult result = provider.queryConnections(LocationType.ANY, "Marienplatz", null, null, LocationType.ANY, "Pasing", - new Date(), true); + new Date(), true, WalkSpeed.NORMAL); System.out.println(result); final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.linkLater); System.out.println(moreResult); @@ -46,7 +47,7 @@ public class MvvProviderLiveTest public void longConnection() throws Exception { final QueryConnectionsResult result = provider.queryConnections(LocationType.ANY, "Starnberg, Arbeitsamt", null, null, LocationType.ANY, - "Ackermannstraße", new Date(), true); + "Ackermannstraße", new Date(), true, WalkSpeed.NORMAL); System.out.println(result); final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.linkLater); System.out.println(moreResult); @@ -56,7 +57,7 @@ public class MvvProviderLiveTest public void connectionBetweenCoordinates() throws Exception { final QueryConnectionsResult result = provider.queryConnections(LocationType.WGS84, "48.165238,11.577473", null, null, LocationType.WGS84, - "47.987199,11.326532", new Date(), true); + "47.987199,11.326532", new Date(), true, WalkSpeed.NORMAL); System.out.println(result); final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.linkLater); System.out.println(moreResult); @@ -66,7 +67,7 @@ public class MvvProviderLiveTest public void connectionBetweenCoordinateAndStation() throws Exception { final QueryConnectionsResult result = provider.queryConnections(LocationType.WGS84, "48.238341,11.478230", null, null, LocationType.ANY, - "Ostbahnhof", new Date(), true); + "Ostbahnhof", new Date(), true, WalkSpeed.NORMAL); System.out.println(result); final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.linkLater); System.out.println(moreResult); @@ -76,7 +77,7 @@ public class MvvProviderLiveTest public void connectionBetweenAddresses() throws Exception { final QueryConnectionsResult result = provider.queryConnections(LocationType.ADDRESS, "München, Maximilianstr. 1", null, null, - LocationType.ADDRESS, "Starnberg, Jahnstraße 50", new Date(), true); + LocationType.ADDRESS, "Starnberg, Jahnstraße 50", new Date(), true, WalkSpeed.NORMAL); System.out.println(result); final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.linkLater); System.out.println(moreResult); diff --git a/test/de/schildbach/pte/live/OebbProviderLiveTest.java b/test/de/schildbach/pte/live/OebbProviderLiveTest.java index e61d12f5..27835137 100644 --- a/test/de/schildbach/pte/live/OebbProviderLiveTest.java +++ b/test/de/schildbach/pte/live/OebbProviderLiveTest.java @@ -24,6 +24,7 @@ import org.junit.Test; import de.schildbach.pte.OebbProvider; import de.schildbach.pte.QueryConnectionsResult; import de.schildbach.pte.NetworkProvider.LocationType; +import de.schildbach.pte.NetworkProvider.WalkSpeed; /** * @author Andreas Schildbach @@ -36,7 +37,7 @@ public class OebbProviderLiveTest public void shortConnection() throws Exception { final QueryConnectionsResult result = provider.queryConnections(LocationType.ANY, "Linz", null, null, LocationType.ANY, "Berlin", new Date(), - true); + true, WalkSpeed.NORMAL); System.out.println(result); final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.linkLater); System.out.println(moreResult); @@ -46,7 +47,7 @@ public class OebbProviderLiveTest public void slowConnection() throws Exception { final QueryConnectionsResult result = provider.queryConnections(LocationType.ANY, "Ramsen, Zoll", null, null, LocationType.ANY, "Azuga", - new Date(), true); + new Date(), true, WalkSpeed.NORMAL); System.out.println(result); final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.linkLater); System.out.println(moreResult); @@ -56,7 +57,7 @@ public class OebbProviderLiveTest public void connectionWithFootway() throws Exception { final QueryConnectionsResult result = provider.queryConnections(LocationType.ANY, "Graz, Haselweg", null, null, LocationType.ADDRESS, - "Innsbruck, Gumppstraße 69", new Date(), true); + "Innsbruck, Gumppstraße 69", new Date(), true, WalkSpeed.NORMAL); System.out.println(result); final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.linkLater); System.out.println(moreResult); @@ -66,7 +67,7 @@ public class OebbProviderLiveTest public void connectionWithFootway2() throws Exception { final QueryConnectionsResult result = provider.queryConnections(LocationType.ANY, "Wien, Krottenbachstraße 110!", null, null, - LocationType.ADDRESS, "Wien, Meidlinger Hauptstraße 1", new Date(), true); + LocationType.ADDRESS, "Wien, Meidlinger Hauptstraße 1", new Date(), true, WalkSpeed.NORMAL); System.out.println(result); final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.linkLater); System.out.println(moreResult); diff --git a/test/de/schildbach/pte/live/SbbProviderLiveTest.java b/test/de/schildbach/pte/live/SbbProviderLiveTest.java index 0131b7da..9a1375c5 100644 --- a/test/de/schildbach/pte/live/SbbProviderLiveTest.java +++ b/test/de/schildbach/pte/live/SbbProviderLiveTest.java @@ -24,6 +24,7 @@ import org.junit.Test; import de.schildbach.pte.QueryConnectionsResult; import de.schildbach.pte.SbbProvider; import de.schildbach.pte.NetworkProvider.LocationType; +import de.schildbach.pte.NetworkProvider.WalkSpeed; /** * @author Andreas Schildbach @@ -36,7 +37,7 @@ public class SbbProviderLiveTest public void shortConnection() throws Exception { final QueryConnectionsResult result = provider.queryConnections(LocationType.ANY, "Zürich!", null, null, LocationType.ANY, "Bern", - new Date(), true); + new Date(), true, WalkSpeed.NORMAL); System.out.println(result); final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.linkLater); System.out.println(moreResult); @@ -46,7 +47,7 @@ public class SbbProviderLiveTest public void slowConnection() throws Exception { final QueryConnectionsResult result = provider.queryConnections(LocationType.ANY, "Schocherswil, Alte Post!", null, null, LocationType.ANY, - "Laconnex, Mollach", new Date(), true); + "Laconnex, Mollach", new Date(), true, WalkSpeed.NORMAL); System.out.println(result); final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.linkLater); System.out.println(moreResult); @@ -56,7 +57,7 @@ public class SbbProviderLiveTest public void connectionWithFootway() throws Exception { final QueryConnectionsResult result = provider.queryConnections(LocationType.ADDRESS, "Spiez, Seestraße 62", null, null, - LocationType.ADDRESS, "Einsiedeln, Erlenmoosweg 24", new Date(), true); + LocationType.ADDRESS, "Einsiedeln, Erlenmoosweg 24", new Date(), true, WalkSpeed.NORMAL); System.out.println(result); final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.linkLater); System.out.println(moreResult);