mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-16 17:39:49 +00:00
Migrate from EnumSet<LocationType> in interfaces to just Set<LocationType>.
This commit is contained in:
parent
d84e0af608
commit
fe5a2a8453
10 changed files with 26 additions and 29 deletions
|
@ -26,7 +26,6 @@ import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Currency;
|
import java.util.Currency;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.EnumSet;
|
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
@ -444,7 +443,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
|
||||||
return result.get();
|
return result.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void appendCoordRequestParameters(final HttpUrl.Builder url, final EnumSet<LocationType> types,
|
private void appendCoordRequestParameters(final HttpUrl.Builder url, final Set<LocationType> types,
|
||||||
final Point coord, final int maxDistance, final int maxLocations) {
|
final Point coord, final int maxDistance, final int maxLocations) {
|
||||||
appendCommonRequestParams(url, "XML");
|
appendCommonRequestParams(url, "XML");
|
||||||
url.addEncodedQueryParameter("coord", ParserUtils.urlEncode(String.format(Locale.ENGLISH, "%.7f:%.7f:%s",
|
url.addEncodedQueryParameter("coord", ParserUtils.urlEncode(String.format(Locale.ENGLISH, "%.7f:%.7f:%s",
|
||||||
|
@ -465,7 +464,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected NearbyLocationsResult xmlCoordRequest(final EnumSet<LocationType> types, final Point coord,
|
protected NearbyLocationsResult xmlCoordRequest(final Set<LocationType> types, final Point coord,
|
||||||
final int maxDistance, final int maxStations) throws IOException {
|
final int maxDistance, final int maxStations) throws IOException {
|
||||||
final HttpUrl.Builder url = coordEndpoint.newBuilder();
|
final HttpUrl.Builder url = coordEndpoint.newBuilder();
|
||||||
appendCoordRequestParameters(url, types, coord, maxDistance, maxStations);
|
appendCoordRequestParameters(url, types, coord, maxDistance, maxStations);
|
||||||
|
@ -533,7 +532,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
|
||||||
return result.get();
|
return result.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected NearbyLocationsResult mobileCoordRequest(final EnumSet<LocationType> types, final Point coord,
|
protected NearbyLocationsResult mobileCoordRequest(final Set<LocationType> types, final Point coord,
|
||||||
final int maxDistance, final int maxStations) throws IOException {
|
final int maxDistance, final int maxStations) throws IOException {
|
||||||
final HttpUrl.Builder url = coordEndpoint.newBuilder();
|
final HttpUrl.Builder url = coordEndpoint.newBuilder();
|
||||||
appendCoordRequestParameters(url, types, coord, maxDistance, maxStations);
|
appendCoordRequestParameters(url, types, coord, maxDistance, maxStations);
|
||||||
|
@ -775,7 +774,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NearbyLocationsResult queryNearbyLocations(final EnumSet<LocationType> types, final Location location,
|
public NearbyLocationsResult queryNearbyLocations(final Set<LocationType> types, final Location location,
|
||||||
final int maxDistance, final int maxLocations) throws IOException {
|
final int maxDistance, final int maxLocations) throws IOException {
|
||||||
if (location.hasCoord())
|
if (location.hasCoord())
|
||||||
return xmlCoordRequest(types, location.coord, maxDistance, maxLocations);
|
return xmlCoordRequest(types, location.coord, maxDistance, maxLocations);
|
||||||
|
|
|
@ -138,7 +138,7 @@ public abstract class AbstractHafasClientInterfaceProvider extends AbstractHafas
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NearbyLocationsResult queryNearbyLocations(final EnumSet<LocationType> types, final Location location,
|
public NearbyLocationsResult queryNearbyLocations(final Set<LocationType> types, final Location location,
|
||||||
final int maxDistance, final int maxLocations) throws IOException {
|
final int maxDistance, final int maxLocations) throws IOException {
|
||||||
if (location.hasCoord())
|
if (location.hasCoord())
|
||||||
return jsonLocGeoPos(types, location.coord, maxDistance, maxLocations);
|
return jsonLocGeoPos(types, location.coord, maxDistance, maxLocations);
|
||||||
|
@ -171,7 +171,7 @@ public abstract class AbstractHafasClientInterfaceProvider extends AbstractHafas
|
||||||
jsonContext.products, jsonContext.walkSpeed, later ? jsonContext.laterContext : jsonContext.earlierContext);
|
jsonContext.products, jsonContext.walkSpeed, later ? jsonContext.laterContext : jsonContext.earlierContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final NearbyLocationsResult jsonLocGeoPos(final EnumSet<LocationType> types, final Point coord,
|
protected final NearbyLocationsResult jsonLocGeoPos(final Set<LocationType> types, final Point coord,
|
||||||
int maxDistance, int maxLocations) throws IOException {
|
int maxDistance, int maxLocations) throws IOException {
|
||||||
if (maxDistance == 0)
|
if (maxDistance == 0)
|
||||||
maxDistance = DEFAULT_MAX_DISTANCE;
|
maxDistance = DEFAULT_MAX_DISTANCE;
|
||||||
|
|
|
@ -31,7 +31,6 @@ import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.EnumSet;
|
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
@ -2195,7 +2194,7 @@ public abstract class AbstractHafasLegacyProvider extends AbstractHafasProvider
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NearbyLocationsResult queryNearbyLocations(final EnumSet<LocationType> types, final Location location,
|
public NearbyLocationsResult queryNearbyLocations(final Set<LocationType> types, final Location location,
|
||||||
final int maxDistance, final int maxLocations) throws IOException {
|
final int maxDistance, final int maxLocations) throws IOException {
|
||||||
if (location.hasCoord())
|
if (location.hasCoord())
|
||||||
return nearbyLocationsByCoordinate(types, location.coord, maxDistance, maxLocations);
|
return nearbyLocationsByCoordinate(types, location.coord, maxDistance, maxLocations);
|
||||||
|
@ -2205,8 +2204,8 @@ public abstract class AbstractHafasLegacyProvider extends AbstractHafasProvider
|
||||||
throw new IllegalArgumentException("cannot handle: " + location);
|
throw new IllegalArgumentException("cannot handle: " + location);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final NearbyLocationsResult nearbyLocationsByCoordinate(final EnumSet<LocationType> types,
|
protected final NearbyLocationsResult nearbyLocationsByCoordinate(final Set<LocationType> types, final Point coord,
|
||||||
final Point coord, final int maxDistance, final int maxLocations) throws IOException {
|
final int maxDistance, final int maxLocations) throws IOException {
|
||||||
if (types.contains(LocationType.STATION)) {
|
if (types.contains(LocationType.STATION)) {
|
||||||
final HttpUrl.Builder url = queryEndpoint.newBuilder().addPathSegment(apiLanguage + "y");
|
final HttpUrl.Builder url = queryEndpoint.newBuilder().addPathSegment(apiLanguage + "y");
|
||||||
appendJsonNearbyStationsParameters(url, coord, maxDistance, maxLocations);
|
appendJsonNearbyStationsParameters(url, coord, maxDistance, maxLocations);
|
||||||
|
|
|
@ -689,7 +689,7 @@ public abstract class AbstractNavitiaProvider extends AbstractNetworkProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NearbyLocationsResult queryNearbyLocations(final EnumSet<LocationType> types, final Location location,
|
public NearbyLocationsResult queryNearbyLocations(final Set<LocationType> types, final Location location,
|
||||||
int maxDistance, final int maxLocations) throws IOException {
|
int maxDistance, final int maxLocations) throws IOException {
|
||||||
final ResultHeader resultHeader = new ResultHeader(network, SERVER_PRODUCT, SERVER_VERSION, null, 0, null);
|
final ResultHeader resultHeader = new ResultHeader(network, SERVER_PRODUCT, SERVER_VERSION, null, 0, null);
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.EnumSet;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ public class BayernProvider extends AbstractEfaProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NearbyLocationsResult queryNearbyLocations(final EnumSet<LocationType> types, final Location location,
|
public NearbyLocationsResult queryNearbyLocations(final Set<LocationType> types, final Location location,
|
||||||
final int maxDistance, final int maxLocations) throws IOException {
|
final int maxDistance, final int maxLocations) throws IOException {
|
||||||
if (location.hasCoord())
|
if (location.hasCoord())
|
||||||
return mobileCoordRequest(types, location.coord, maxDistance, maxLocations);
|
return mobileCoordRequest(types, location.coord, maxDistance, maxLocations);
|
||||||
|
|
|
@ -195,7 +195,7 @@ public class NegentweeProvider extends AbstractNetworkProvider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Location queryLocationByName(String locationName, EnumSet<LocationType> types) throws IOException {
|
private Location queryLocationByName(String locationName, Set<LocationType> types) throws IOException {
|
||||||
for (Location location : queryLocationsByName(locationName, types)) {
|
for (Location location : queryLocationsByName(locationName, types)) {
|
||||||
if (location.name != null && location.name.equals(locationName)) {
|
if (location.name != null && location.name.equals(locationName)) {
|
||||||
return location;
|
return location;
|
||||||
|
@ -205,7 +205,7 @@ public class NegentweeProvider extends AbstractNetworkProvider {
|
||||||
throw new RuntimeException("Cannot find station with name " + locationName);
|
throw new RuntimeException("Cannot find station with name " + locationName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Location> queryLocationsByName(String locationName, EnumSet<LocationType> types) throws IOException {
|
private List<Location> queryLocationsByName(String locationName, Set<LocationType> types) throws IOException {
|
||||||
List<QueryParameter> queryParameters = new ArrayList<>();
|
List<QueryParameter> queryParameters = new ArrayList<>();
|
||||||
queryParameters.add(new QueryParameter("q", locationName));
|
queryParameters.add(new QueryParameter("q", locationName));
|
||||||
|
|
||||||
|
@ -267,7 +267,7 @@ public class NegentweeProvider extends AbstractNetworkProvider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private EnumSet<Product> productSetFromTypeString(String type) {
|
private Set<Product> productSetFromTypeString(String type) {
|
||||||
switch (type.toLowerCase()) {
|
switch (type.toLowerCase()) {
|
||||||
case "train":
|
case "train":
|
||||||
return EnumSet.of(Product.HIGH_SPEED_TRAIN, Product.REGIONAL_TRAIN, Product.SUBURBAN_TRAIN);
|
return EnumSet.of(Product.HIGH_SPEED_TRAIN, Product.REGIONAL_TRAIN, Product.SUBURBAN_TRAIN);
|
||||||
|
@ -328,7 +328,7 @@ public class NegentweeProvider extends AbstractNetworkProvider {
|
||||||
// Including these type names will cause the locations API to fail, skip them
|
// Including these type names will cause the locations API to fail, skip them
|
||||||
private static final ImmutableSet<String> DISALLOWED_TYPE_NAMES = ImmutableSet.of("latlong", "streetrange");
|
private static final ImmutableSet<String> DISALLOWED_TYPE_NAMES = ImmutableSet.of("latlong", "streetrange");
|
||||||
|
|
||||||
private String locationTypesToQueryParameterString(EnumSet<LocationType> types) {
|
private String locationTypesToQueryParameterString(Set<LocationType> types) {
|
||||||
StringBuilder typeValue = new StringBuilder();
|
StringBuilder typeValue = new StringBuilder();
|
||||||
if (!types.contains(LocationType.ANY) && types.size() > 0) {
|
if (!types.contains(LocationType.ANY) && types.size() > 0) {
|
||||||
for (LocationType type : types) {
|
for (LocationType type : types) {
|
||||||
|
@ -708,7 +708,7 @@ public class NegentweeProvider extends AbstractNetworkProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NearbyLocationsResult queryNearbyLocations(EnumSet<LocationType> types, Location location, int maxDistance,
|
public NearbyLocationsResult queryNearbyLocations(Set<LocationType> types, Location location, int maxDistance,
|
||||||
int maxLocations) throws IOException {
|
int maxLocations) throws IOException {
|
||||||
// Coordinates are required
|
// Coordinates are required
|
||||||
if (!location.hasCoord()) {
|
if (!location.hasCoord()) {
|
||||||
|
|
|
@ -19,7 +19,6 @@ package de.schildbach.pte;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.EnumSet;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
@ -88,7 +87,7 @@ public interface NetworkProvider {
|
||||||
* @return nearby stations
|
* @return nearby stations
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
NearbyLocationsResult queryNearbyLocations(EnumSet<LocationType> types, Location location, int maxDistance,
|
NearbyLocationsResult queryNearbyLocations(Set<LocationType> types, Location location, int maxDistance,
|
||||||
int maxLocations) throws IOException;
|
int maxLocations) throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -21,7 +21,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.EnumSet;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ public class StvProvider extends AbstractEfaProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NearbyLocationsResult queryNearbyLocations(final EnumSet<LocationType> types, final Location location,
|
public NearbyLocationsResult queryNearbyLocations(final Set<LocationType> types, final Location location,
|
||||||
final int maxDistance, final int maxLocations) throws IOException {
|
final int maxDistance, final int maxLocations) throws IOException {
|
||||||
if (location.hasCoord())
|
if (location.hasCoord())
|
||||||
return mobileCoordRequest(types, location.coord, maxDistance, maxLocations);
|
return mobileCoordRequest(types, location.coord, maxDistance, maxLocations);
|
||||||
|
|
|
@ -28,7 +28,6 @@ import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Currency;
|
import java.util.Currency;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.EnumSet;
|
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
@ -358,7 +357,7 @@ public class VrsProvider extends AbstractNetworkProvider {
|
||||||
|
|
||||||
// only stations supported
|
// only stations supported
|
||||||
@Override
|
@Override
|
||||||
public NearbyLocationsResult queryNearbyLocations(EnumSet<LocationType> types /* only STATION supported */,
|
public NearbyLocationsResult queryNearbyLocations(Set<LocationType> types /* only STATION supported */,
|
||||||
Location location, int maxDistance, int maxLocations) throws IOException {
|
Location location, int maxDistance, int maxLocations) throws IOException {
|
||||||
// g=p means group by product; not used here
|
// g=p means group by product; not used here
|
||||||
final HttpUrl.Builder url = API_BASE.newBuilder();
|
final HttpUrl.Builder url = API_BASE.newBuilder();
|
||||||
|
|
|
@ -24,6 +24,7 @@ import java.io.InputStream;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
@ -84,13 +85,13 @@ public abstract class AbstractProviderLiveTest {
|
||||||
return queryNearbyLocations(EnumSet.of(LocationType.STATION), location, 0, 5);
|
return queryNearbyLocations(EnumSet.of(LocationType.STATION), location, 0, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final NearbyLocationsResult queryNearbyLocations(final EnumSet<LocationType> types,
|
protected final NearbyLocationsResult queryNearbyLocations(final Set<LocationType> types, final Location location)
|
||||||
final Location location) throws IOException {
|
throws IOException {
|
||||||
return queryNearbyLocations(types, location, 0, 5);
|
return queryNearbyLocations(types, location, 0, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final NearbyLocationsResult queryNearbyLocations(final EnumSet<LocationType> types,
|
protected final NearbyLocationsResult queryNearbyLocations(final Set<LocationType> types, final Location location,
|
||||||
final Location location, final int maxDistance, final int maxStations) throws IOException {
|
final int maxDistance, final int maxStations) throws IOException {
|
||||||
return provider.queryNearbyLocations(types, location, maxDistance, maxStations);
|
return provider.queryNearbyLocations(types, location, maxDistance, maxStations);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue