Optionally disable sort by weight in JSON getstops (Hafas).

This commit is contained in:
Andreas Schildbach 2014-08-14 10:48:45 +02:00
parent c11a23ba08
commit 8adf98b98e
4 changed files with 23 additions and 2 deletions

View file

@ -89,6 +89,7 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider
private String accessId; private String accessId;
private String clientType; private String clientType;
private Charset jsonGetStopsEncoding; private Charset jsonGetStopsEncoding;
private boolean jsonGetStopsUseWeight = true;
private Charset jsonNearbyStationsEncoding; private Charset jsonNearbyStationsEncoding;
private boolean dominantPlanStopTime = false; private boolean dominantPlanStopTime = false;
private boolean useIso8601 = false; private boolean useIso8601 = false;
@ -183,6 +184,11 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider
this.jsonGetStopsEncoding = jsonGetStopsEncoding; this.jsonGetStopsEncoding = jsonGetStopsEncoding;
} }
protected void setJsonGetStopsUseWeight(final boolean jsonGetStopsUseWeight)
{
this.jsonGetStopsUseWeight = jsonGetStopsUseWeight;
}
protected void setJsonNearbyStationsEncoding(final Charset jsonNearbyStationsEncoding) protected void setJsonNearbyStationsEncoding(final Charset jsonNearbyStationsEncoding)
{ {
this.jsonNearbyStationsEncoding = jsonNearbyStationsEncoding; this.jsonNearbyStationsEncoding = jsonNearbyStationsEncoding;
@ -372,7 +378,7 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider
final String value = suggestion.getString("value"); final String value = suggestion.getString("value");
final int lat = suggestion.optInt("ycoord"); final int lat = suggestion.optInt("ycoord");
final int lon = suggestion.optInt("xcoord"); final int lon = suggestion.optInt("xcoord");
final int weight = suggestion.getInt("weight"); final int weight = jsonGetStopsUseWeight ? suggestion.getInt("weight") : -i;
String localId = null; String localId = null;
final Matcher m = P_AJAX_GET_STOPS_ID.matcher(suggestion.getString("id")); final Matcher m = P_AJAX_GET_STOPS_ID.matcher(suggestion.getString("id"));
if (m.matches()) if (m.matches())

View file

@ -63,6 +63,7 @@ public final class BvgProvider extends AbstractHafasProvider
super(API_BASE + "stboard.bin/dn", API_BASE + "ajax-getstop.bin/dny", API_BASE + "query.bin/dn", 8, UTF_8); super(API_BASE + "stboard.bin/dn", API_BASE + "ajax-getstop.bin/dny", API_BASE + "query.bin/dn", 8, UTF_8);
setStyles(STYLES); setStyles(STYLES);
setJsonGetStopsUseWeight(false);
this.additionalQueryParameter = additionalQueryParameter; this.additionalQueryParameter = additionalQueryParameter;
} }

View file

@ -155,7 +155,11 @@ public final class Location implements Serializable
return this.id.equals(other.id); return this.id.equals(other.id);
if (this.lat != 0 && this.lon != 0) if (this.lat != 0 && this.lon != 0)
return this.lat == other.lat && this.lon == other.lon; return this.lat == other.lat && this.lon == other.lon;
if (!nullSafeEquals(this.name, other.name)) // only discriminate by name if no ids are given
// only discriminate by name/place if no ids are given
if (!nullSafeEquals(this.name, other.name))
return false;
if (!nullSafeEquals(this.place, other.place))
return false; return false;
return true; return true;
} }

View file

@ -100,6 +100,16 @@ public class BvgProviderLiveTest extends AbstractProviderLiveTest
Assert.assertEquals("Güntzelstr. (U)", result.getLocations().get(0).name); Assert.assertEquals("Güntzelstr. (U)", result.getLocations().get(0).name);
} }
@Test
public void suggestLocationsLocality() throws Exception
{
final SuggestLocationsResult result = provider.suggestLocations("seeling");
print(result);
Assert.assertEquals(new Location(LocationType.STATION, null, "Berlin", "Seelingstr."), result.getLocations().get(0));
}
@Test @Test
public void suggestLocationsAddress() throws Exception public void suggestLocationsAddress() throws Exception
{ {