Migrate from EnumSet<LocationType> in interfaces to just Set<LocationType>.

This commit is contained in:
Andreas Schildbach 2018-12-23 14:08:40 +01:00
parent d84e0af608
commit fe5a2a8453
10 changed files with 26 additions and 29 deletions

View file

@ -26,7 +26,6 @@ import java.util.ArrayList;
import java.util.Calendar;
import java.util.Currency;
import java.util.Date;
import java.util.EnumSet;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.HashSet;
@ -444,7 +443,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
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) {
appendCommonRequestParams(url, "XML");
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 HttpUrl.Builder url = coordEndpoint.newBuilder();
appendCoordRequestParameters(url, types, coord, maxDistance, maxStations);
@ -533,7 +532,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
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 HttpUrl.Builder url = coordEndpoint.newBuilder();
appendCoordRequestParameters(url, types, coord, maxDistance, maxStations);
@ -775,7 +774,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
}
@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 {
if (location.hasCoord())
return xmlCoordRequest(types, location.coord, maxDistance, maxLocations);

View file

@ -138,7 +138,7 @@ public abstract class AbstractHafasClientInterfaceProvider extends AbstractHafas
}
@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 {
if (location.hasCoord())
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);
}
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 {
if (maxDistance == 0)
maxDistance = DEFAULT_MAX_DISTANCE;

View file

@ -31,7 +31,6 @@ import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.EnumSet;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.HashSet;
@ -2195,7 +2194,7 @@ public abstract class AbstractHafasLegacyProvider extends AbstractHafasProvider
}
@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 {
if (location.hasCoord())
return nearbyLocationsByCoordinate(types, location.coord, maxDistance, maxLocations);
@ -2205,8 +2204,8 @@ public abstract class AbstractHafasLegacyProvider extends AbstractHafasProvider
throw new IllegalArgumentException("cannot handle: " + location);
}
protected final NearbyLocationsResult nearbyLocationsByCoordinate(final EnumSet<LocationType> types,
final Point coord, final int maxDistance, final int maxLocations) throws IOException {
protected final NearbyLocationsResult nearbyLocationsByCoordinate(final Set<LocationType> types, final Point coord,
final int maxDistance, final int maxLocations) throws IOException {
if (types.contains(LocationType.STATION)) {
final HttpUrl.Builder url = queryEndpoint.newBuilder().addPathSegment(apiLanguage + "y");
appendJsonNearbyStationsParameters(url, coord, maxDistance, maxLocations);

View file

@ -689,7 +689,7 @@ public abstract class AbstractNavitiaProvider extends AbstractNetworkProvider {
}
@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 {
final ResultHeader resultHeader = new ResultHeader(network, SERVER_PRODUCT, SERVER_VERSION, null, 0, null);

View file

@ -21,7 +21,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
import java.io.IOException;
import java.util.Date;
import java.util.EnumSet;
import java.util.Set;
import javax.annotation.Nullable;
@ -110,7 +110,7 @@ public class BayernProvider extends AbstractEfaProvider {
}
@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 {
if (location.hasCoord())
return mobileCoordRequest(types, location.coord, maxDistance, maxLocations);

View file

@ -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)) {
if (location.name != null && location.name.equals(locationName)) {
return location;
@ -205,7 +205,7 @@ public class NegentweeProvider extends AbstractNetworkProvider {
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<>();
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()) {
case "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
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();
if (!types.contains(LocationType.ANY) && types.size() > 0) {
for (LocationType type : types) {
@ -708,7 +708,7 @@ public class NegentweeProvider extends AbstractNetworkProvider {
}
@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 {
// Coordinates are required
if (!location.hasCoord()) {

View file

@ -19,7 +19,6 @@ package de.schildbach.pte;
import java.io.IOException;
import java.util.Date;
import java.util.EnumSet;
import java.util.Set;
import javax.annotation.Nullable;
@ -88,7 +87,7 @@ public interface NetworkProvider {
* @return nearby stations
* @throws IOException
*/
NearbyLocationsResult queryNearbyLocations(EnumSet<LocationType> types, Location location, int maxDistance,
NearbyLocationsResult queryNearbyLocations(Set<LocationType> types, Location location, int maxDistance,
int maxLocations) throws IOException;
/**

View file

@ -21,7 +21,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
import java.io.IOException;
import java.util.Date;
import java.util.EnumSet;
import java.util.Set;
import javax.annotation.Nullable;
@ -52,7 +52,7 @@ public class StvProvider extends AbstractEfaProvider {
}
@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 {
if (location.hasCoord())
return mobileCoordRequest(types, location.coord, maxDistance, maxLocations);

View file

@ -28,7 +28,6 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.Currency;
import java.util.Date;
import java.util.EnumSet;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.HashSet;
@ -358,7 +357,7 @@ public class VrsProvider extends AbstractNetworkProvider {
// only stations supported
@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 {
// g=p means group by product; not used here
final HttpUrl.Builder url = API_BASE.newBuilder();

View file

@ -24,6 +24,7 @@ import java.io.InputStream;
import java.util.Date;
import java.util.EnumSet;
import java.util.Properties;
import java.util.Set;
import javax.annotation.Nullable;
@ -84,13 +85,13 @@ public abstract class AbstractProviderLiveTest {
return queryNearbyLocations(EnumSet.of(LocationType.STATION), location, 0, 5);
}
protected final NearbyLocationsResult queryNearbyLocations(final EnumSet<LocationType> types,
final Location location) throws IOException {
protected final NearbyLocationsResult queryNearbyLocations(final Set<LocationType> types, final Location location)
throws IOException {
return queryNearbyLocations(types, location, 0, 5);
}
protected final NearbyLocationsResult queryNearbyLocations(final EnumSet<LocationType> types,
final Location location, final int maxDistance, final int maxStations) throws IOException {
protected final NearbyLocationsResult queryNearbyLocations(final Set<LocationType> types, final Location location,
final int maxDistance, final int maxStations) throws IOException {
return provider.queryNearbyLocations(types, location, maxDistance, maxStations);
}