mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-07 22:18:49 +00:00
Refactor hasCapability() implementations to use internal arrays of capabilities.
This commit is contained in:
parent
949b69a443
commit
30e6971a61
5 changed files with 47 additions and 28 deletions
|
@ -23,6 +23,7 @@ import static com.google.common.base.Preconditions.checkState;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Currency;
|
import java.util.Currency;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
@ -96,6 +97,13 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
|
||||||
protected static final String COORD_FORMAT = "WGS84[DD.ddddd]";
|
protected static final String COORD_FORMAT = "WGS84[DD.ddddd]";
|
||||||
protected static final int COORD_FORMAT_TAIL = 7;
|
protected static final int COORD_FORMAT_TAIL = 7;
|
||||||
|
|
||||||
|
private final List CAPABILITIES = Arrays.asList(
|
||||||
|
Capability.SUGGEST_LOCATIONS,
|
||||||
|
Capability.NEARBY_LOCATIONS,
|
||||||
|
Capability.DEPARTURES,
|
||||||
|
Capability.TRIPS
|
||||||
|
);
|
||||||
|
|
||||||
private final HttpUrl departureMonitorEndpoint;
|
private final HttpUrl departureMonitorEndpoint;
|
||||||
private final HttpUrl tripEndpoint;
|
private final HttpUrl tripEndpoint;
|
||||||
private final HttpUrl stopFinderEndpoint;
|
private final HttpUrl stopFinderEndpoint;
|
||||||
|
@ -228,9 +236,10 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// this should be overridden by networks not providing one of the default capabilities
|
||||||
@Override
|
@Override
|
||||||
protected boolean hasCapability(final Capability capability) {
|
protected boolean hasCapability(final Capability capability) {
|
||||||
return true;
|
return CAPABILITIES.contains(capability);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void appendCommonRequestParams(final HttpUrl.Builder url, final String outputFormat) {
|
private final void appendCommonRequestParams(final HttpUrl.Builder url, final String outputFormat) {
|
||||||
|
|
|
@ -20,6 +20,7 @@ package de.schildbach.pte;
|
||||||
import static com.google.common.base.Preconditions.checkArgument;
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
import static com.google.common.base.Preconditions.checkState;
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -43,6 +44,13 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider {
|
||||||
protected static final int DEFAULT_MAX_LOCATIONS = 50;
|
protected static final int DEFAULT_MAX_LOCATIONS = 50;
|
||||||
protected static final int DEFAULT_MAX_DISTANCE = 20000;
|
protected static final int DEFAULT_MAX_DISTANCE = 20000;
|
||||||
|
|
||||||
|
private final List CAPABILITIES = Arrays.asList(
|
||||||
|
Capability.SUGGEST_LOCATIONS,
|
||||||
|
Capability.NEARBY_LOCATIONS,
|
||||||
|
Capability.DEPARTURES,
|
||||||
|
Capability.TRIPS
|
||||||
|
);
|
||||||
|
|
||||||
protected static final Logger log = LoggerFactory.getLogger(AbstractHafasProvider.class);
|
protected static final Logger log = LoggerFactory.getLogger(AbstractHafasProvider.class);
|
||||||
|
|
||||||
private Product[] productsMap;
|
private Product[] productsMap;
|
||||||
|
@ -52,9 +60,10 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider {
|
||||||
this.productsMap = productsMap;
|
this.productsMap = productsMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// this should be overridden by networks not providing one of the default capabilities
|
||||||
@Override
|
@Override
|
||||||
protected boolean hasCapability(final Capability capability) {
|
protected boolean hasCapability(final Capability capability) {
|
||||||
return true;
|
return CAPABILITIES.contains(capability);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final CharSequence productsString(final Set<Product> products) {
|
protected final CharSequence productsString(final Set<Product> products) {
|
||||||
|
|
|
@ -24,6 +24,7 @@ import java.text.DateFormat;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
@ -78,6 +79,13 @@ public abstract class AbstractNavitiaProvider extends AbstractNetworkProvider {
|
||||||
protected final static String SERVER_PRODUCT = "navitia";
|
protected final static String SERVER_PRODUCT = "navitia";
|
||||||
protected final static String SERVER_VERSION = "v1";
|
protected final static String SERVER_VERSION = "v1";
|
||||||
|
|
||||||
|
private final List CAPABILITIES = Arrays.asList(
|
||||||
|
Capability.SUGGEST_LOCATIONS,
|
||||||
|
Capability.NEARBY_LOCATIONS,
|
||||||
|
Capability.DEPARTURES,
|
||||||
|
Capability.TRIPS
|
||||||
|
);
|
||||||
|
|
||||||
protected HttpUrl apiBase = HttpUrl.parse("https://api.navitia.io/").newBuilder().addPathSegment(SERVER_VERSION)
|
protected HttpUrl apiBase = HttpUrl.parse("https://api.navitia.io/").newBuilder().addPathSegment(SERVER_VERSION)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
@ -680,13 +688,10 @@ public abstract class AbstractNavitiaProvider extends AbstractNetworkProvider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// this should be overridden by networks not providing one of the default capabilities
|
||||||
@Override
|
@Override
|
||||||
protected boolean hasCapability(final Capability capability) {
|
protected boolean hasCapability(final Capability capability) {
|
||||||
if (capability == Capability.SUGGEST_LOCATIONS || capability == Capability.NEARBY_LOCATIONS
|
return CAPABILITIES.contains(capability);
|
||||||
|| capability == Capability.DEPARTURES || capability == Capability.TRIPS)
|
|
||||||
return true;
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -80,6 +80,13 @@ public class NegentweeProvider extends AbstractNetworkProvider {
|
||||||
private static final TimeZone API_TIMEZONE = TimeZone.getTimeZone("Europe/Amsterdam");
|
private static final TimeZone API_TIMEZONE = TimeZone.getTimeZone("Europe/Amsterdam");
|
||||||
private static final int DEFAULT_MAX_LOCATIONS = 50;
|
private static final int DEFAULT_MAX_LOCATIONS = 50;
|
||||||
|
|
||||||
|
private final List CAPABILITIES = Arrays.asList(
|
||||||
|
Capability.SUGGEST_LOCATIONS,
|
||||||
|
Capability.NEARBY_LOCATIONS,
|
||||||
|
Capability.DEPARTURES,
|
||||||
|
Capability.TRIPS
|
||||||
|
);
|
||||||
|
|
||||||
private static final EnumSet<Product> trainProducts = EnumSet.of(Product.HIGH_SPEED_TRAIN, Product.REGIONAL_TRAIN,
|
private static final EnumSet<Product> trainProducts = EnumSet.of(Product.HIGH_SPEED_TRAIN, Product.REGIONAL_TRAIN,
|
||||||
Product.SUBURBAN_TRAIN);
|
Product.SUBURBAN_TRAIN);
|
||||||
|
|
||||||
|
@ -698,15 +705,7 @@ public class NegentweeProvider extends AbstractNetworkProvider {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean hasCapability(Capability capability) {
|
protected boolean hasCapability(Capability capability) {
|
||||||
switch (capability) {
|
return CAPABILITIES.contains(capability);
|
||||||
case SUGGEST_LOCATIONS:
|
|
||||||
case NEARBY_LOCATIONS:
|
|
||||||
case DEPARTURES:
|
|
||||||
case TRIPS:
|
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -23,6 +23,7 @@ import java.io.IOException;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
@ -81,6 +82,13 @@ import okhttp3.HttpUrl;
|
||||||
*/
|
*/
|
||||||
public class VrsProvider extends AbstractNetworkProvider {
|
public class VrsProvider extends AbstractNetworkProvider {
|
||||||
|
|
||||||
|
private final List CAPABILITIES = Arrays.asList(
|
||||||
|
Capability.SUGGEST_LOCATIONS,
|
||||||
|
Capability.NEARBY_LOCATIONS,
|
||||||
|
Capability.DEPARTURES,
|
||||||
|
Capability.TRIPS
|
||||||
|
);
|
||||||
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(VrsProvider.class);
|
private static final Logger log = LoggerFactory.getLogger(VrsProvider.class);
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
|
@ -342,18 +350,7 @@ public class VrsProvider extends AbstractNetworkProvider {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean hasCapability(Capability capability) {
|
protected boolean hasCapability(Capability capability) {
|
||||||
switch (capability) {
|
return CAPABILITIES.contains(capability);
|
||||||
case DEPARTURES:
|
|
||||||
return true;
|
|
||||||
case NEARBY_LOCATIONS:
|
|
||||||
return true;
|
|
||||||
case SUGGEST_LOCATIONS:
|
|
||||||
return true;
|
|
||||||
case TRIPS:
|
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// only stations supported
|
// only stations supported
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue