From fe5a2a8453b95bdcd0816bdf66b5bdc943513468 Mon Sep 17 00:00:00 2001 From: Andreas Schildbach Date: Sun, 23 Dec 2018 14:08:40 +0100 Subject: [PATCH] Migrate from EnumSet in interfaces to just Set. --- enabler/src/de/schildbach/pte/AbstractEfaProvider.java | 9 ++++----- .../pte/AbstractHafasClientInterfaceProvider.java | 4 ++-- .../de/schildbach/pte/AbstractHafasLegacyProvider.java | 7 +++---- .../src/de/schildbach/pte/AbstractNavitiaProvider.java | 2 +- enabler/src/de/schildbach/pte/BayernProvider.java | 4 ++-- enabler/src/de/schildbach/pte/NegentweeProvider.java | 10 +++++----- enabler/src/de/schildbach/pte/NetworkProvider.java | 3 +-- enabler/src/de/schildbach/pte/StvProvider.java | 4 ++-- enabler/src/de/schildbach/pte/VrsProvider.java | 3 +-- .../schildbach/pte/live/AbstractProviderLiveTest.java | 9 +++++---- 10 files changed, 26 insertions(+), 29 deletions(-) diff --git a/enabler/src/de/schildbach/pte/AbstractEfaProvider.java b/enabler/src/de/schildbach/pte/AbstractEfaProvider.java index fad195d4..7bed2195 100644 --- a/enabler/src/de/schildbach/pte/AbstractEfaProvider.java +++ b/enabler/src/de/schildbach/pte/AbstractEfaProvider.java @@ -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 types, + private void appendCoordRequestParameters(final HttpUrl.Builder url, final Set 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 types, final Point coord, + protected NearbyLocationsResult xmlCoordRequest(final Set 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 types, final Point coord, + protected NearbyLocationsResult mobileCoordRequest(final Set 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 types, final Location location, + public NearbyLocationsResult queryNearbyLocations(final Set types, final Location location, final int maxDistance, final int maxLocations) throws IOException { if (location.hasCoord()) return xmlCoordRequest(types, location.coord, maxDistance, maxLocations); diff --git a/enabler/src/de/schildbach/pte/AbstractHafasClientInterfaceProvider.java b/enabler/src/de/schildbach/pte/AbstractHafasClientInterfaceProvider.java index 0e949f95..20fee7ca 100644 --- a/enabler/src/de/schildbach/pte/AbstractHafasClientInterfaceProvider.java +++ b/enabler/src/de/schildbach/pte/AbstractHafasClientInterfaceProvider.java @@ -138,7 +138,7 @@ public abstract class AbstractHafasClientInterfaceProvider extends AbstractHafas } @Override - public NearbyLocationsResult queryNearbyLocations(final EnumSet types, final Location location, + public NearbyLocationsResult queryNearbyLocations(final Set 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 types, final Point coord, + protected final NearbyLocationsResult jsonLocGeoPos(final Set types, final Point coord, int maxDistance, int maxLocations) throws IOException { if (maxDistance == 0) maxDistance = DEFAULT_MAX_DISTANCE; diff --git a/enabler/src/de/schildbach/pte/AbstractHafasLegacyProvider.java b/enabler/src/de/schildbach/pte/AbstractHafasLegacyProvider.java index e6fdc3dd..168333ef 100644 --- a/enabler/src/de/schildbach/pte/AbstractHafasLegacyProvider.java +++ b/enabler/src/de/schildbach/pte/AbstractHafasLegacyProvider.java @@ -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 types, final Location location, + public NearbyLocationsResult queryNearbyLocations(final Set 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 types, - final Point coord, final int maxDistance, final int maxLocations) throws IOException { + protected final NearbyLocationsResult nearbyLocationsByCoordinate(final Set 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); diff --git a/enabler/src/de/schildbach/pte/AbstractNavitiaProvider.java b/enabler/src/de/schildbach/pte/AbstractNavitiaProvider.java index b9d01e7f..6b2126fd 100644 --- a/enabler/src/de/schildbach/pte/AbstractNavitiaProvider.java +++ b/enabler/src/de/schildbach/pte/AbstractNavitiaProvider.java @@ -689,7 +689,7 @@ public abstract class AbstractNavitiaProvider extends AbstractNetworkProvider { } @Override - public NearbyLocationsResult queryNearbyLocations(final EnumSet types, final Location location, + public NearbyLocationsResult queryNearbyLocations(final Set types, final Location location, int maxDistance, final int maxLocations) throws IOException { final ResultHeader resultHeader = new ResultHeader(network, SERVER_PRODUCT, SERVER_VERSION, null, 0, null); diff --git a/enabler/src/de/schildbach/pte/BayernProvider.java b/enabler/src/de/schildbach/pte/BayernProvider.java index 7ddaef00..ac6cac46 100644 --- a/enabler/src/de/schildbach/pte/BayernProvider.java +++ b/enabler/src/de/schildbach/pte/BayernProvider.java @@ -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 types, final Location location, + public NearbyLocationsResult queryNearbyLocations(final Set types, final Location location, final int maxDistance, final int maxLocations) throws IOException { if (location.hasCoord()) return mobileCoordRequest(types, location.coord, maxDistance, maxLocations); diff --git a/enabler/src/de/schildbach/pte/NegentweeProvider.java b/enabler/src/de/schildbach/pte/NegentweeProvider.java index 7eb53cb2..095cef38 100644 --- a/enabler/src/de/schildbach/pte/NegentweeProvider.java +++ b/enabler/src/de/schildbach/pte/NegentweeProvider.java @@ -195,7 +195,7 @@ public class NegentweeProvider extends AbstractNetworkProvider { } } - private Location queryLocationByName(String locationName, EnumSet types) throws IOException { + private Location queryLocationByName(String locationName, Set 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 queryLocationsByName(String locationName, EnumSet types) throws IOException { + private List queryLocationsByName(String locationName, Set types) throws IOException { List queryParameters = new ArrayList<>(); queryParameters.add(new QueryParameter("q", locationName)); @@ -267,7 +267,7 @@ public class NegentweeProvider extends AbstractNetworkProvider { } } - private EnumSet productSetFromTypeString(String type) { + private Set 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 DISALLOWED_TYPE_NAMES = ImmutableSet.of("latlong", "streetrange"); - private String locationTypesToQueryParameterString(EnumSet types) { + private String locationTypesToQueryParameterString(Set 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 types, Location location, int maxDistance, + public NearbyLocationsResult queryNearbyLocations(Set types, Location location, int maxDistance, int maxLocations) throws IOException { // Coordinates are required if (!location.hasCoord()) { diff --git a/enabler/src/de/schildbach/pte/NetworkProvider.java b/enabler/src/de/schildbach/pte/NetworkProvider.java index 47545822..d19a0e1f 100644 --- a/enabler/src/de/schildbach/pte/NetworkProvider.java +++ b/enabler/src/de/schildbach/pte/NetworkProvider.java @@ -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 types, Location location, int maxDistance, + NearbyLocationsResult queryNearbyLocations(Set types, Location location, int maxDistance, int maxLocations) throws IOException; /** diff --git a/enabler/src/de/schildbach/pte/StvProvider.java b/enabler/src/de/schildbach/pte/StvProvider.java index abc90230..547e1410 100644 --- a/enabler/src/de/schildbach/pte/StvProvider.java +++ b/enabler/src/de/schildbach/pte/StvProvider.java @@ -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 types, final Location location, + public NearbyLocationsResult queryNearbyLocations(final Set types, final Location location, final int maxDistance, final int maxLocations) throws IOException { if (location.hasCoord()) return mobileCoordRequest(types, location.coord, maxDistance, maxLocations); diff --git a/enabler/src/de/schildbach/pte/VrsProvider.java b/enabler/src/de/schildbach/pte/VrsProvider.java index 23a4f0f8..1b5c5304 100644 --- a/enabler/src/de/schildbach/pte/VrsProvider.java +++ b/enabler/src/de/schildbach/pte/VrsProvider.java @@ -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 types /* only STATION supported */, + public NearbyLocationsResult queryNearbyLocations(Set 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(); diff --git a/enabler/test/de/schildbach/pte/live/AbstractProviderLiveTest.java b/enabler/test/de/schildbach/pte/live/AbstractProviderLiveTest.java index 8378c46c..8535818f 100644 --- a/enabler/test/de/schildbach/pte/live/AbstractProviderLiveTest.java +++ b/enabler/test/de/schildbach/pte/live/AbstractProviderLiveTest.java @@ -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 types, - final Location location) throws IOException { + protected final NearbyLocationsResult queryNearbyLocations(final Set types, final Location location) + throws IOException { return queryNearbyLocations(types, location, 0, 5); } - protected final NearbyLocationsResult queryNearbyLocations(final EnumSet types, - final Location location, final int maxDistance, final int maxStations) throws IOException { + protected final NearbyLocationsResult queryNearbyLocations(final Set types, final Location location, + final int maxDistance, final int maxStations) throws IOException { return provider.queryNearbyLocations(types, location, maxDistance, maxStations); }