From 3b38a48bff02e6851fe8cdc99ad191a5aec96d9d Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Sat, 21 Oct 2017 22:24:45 +0200 Subject: [PATCH] DSB: Normalize a bus name. Also fix a test in DsbProviderLiveTest. --- enabler/src/de/schildbach/pte/DsbProvider.java | 16 +++++++++++++++- .../schildbach/pte/live/DsbProviderLiveTest.java | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/enabler/src/de/schildbach/pte/DsbProvider.java b/enabler/src/de/schildbach/pte/DsbProvider.java index 24e7fe75..34aafa12 100644 --- a/enabler/src/de/schildbach/pte/DsbProvider.java +++ b/enabler/src/de/schildbach/pte/DsbProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 the original author or authors. + * Copyright 2010-2017 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,6 +19,7 @@ package de.schildbach.pte; import java.util.Set; import java.util.regex.Matcher; +import java.util.regex.Pattern; import de.schildbach.pte.dto.Product; @@ -99,4 +100,17 @@ public class DsbProvider extends AbstractHafasLegacyProvider { return super.normalizeType(type); } + + // Busses line name is formatted as "42#Bus 42" but we just want "42" + private static final Pattern P_NORMALIZE_LINE_NAME_BUS_DSB = Pattern.compile(".*?#Bus (.*)", + Pattern.CASE_INSENSITIVE); + + @Override + protected String normalizeLineName(final String lineName) { + final Matcher mBus = P_NORMALIZE_LINE_NAME_BUS_DSB.matcher(lineName); + if (mBus.matches()) + return mBus.group(1); + + return super.normalizeLineName(lineName); + } } diff --git a/enabler/test/de/schildbach/pte/live/DsbProviderLiveTest.java b/enabler/test/de/schildbach/pte/live/DsbProviderLiveTest.java index a7ae6638..2e8b7b09 100644 --- a/enabler/test/de/schildbach/pte/live/DsbProviderLiveTest.java +++ b/enabler/test/de/schildbach/pte/live/DsbProviderLiveTest.java @@ -76,7 +76,7 @@ public class DsbProviderLiveTest extends AbstractProviderLiveTest { public void shortTrip() throws Exception { final QueryTripsResult result = queryTrips( new Location(LocationType.STATION, "900000011", null, "Copenhagen Airport"), null, - new Location(LocationType.STATION, "551922500", null, "Billund Airport"), new Date(), true, Product.ALL, + new Location(LocationType.POI, "551922500", null, "Billund Airport"), new Date(), true, Product.ALL, WalkSpeed.NORMAL, Accessibility.NEUTRAL); print(result); final QueryTripsResult laterResult = queryMoreTrips(result.context, true);