mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-20 17:29:51 +00:00
Hafas: Declare individual product map for each provider, rather than implementing intToProduct() and setProductBits().
This commit is contained in:
parent
5048e826dc
commit
fb6e71ee2b
27 changed files with 136 additions and 1676 deletions
|
@ -33,77 +33,18 @@ import de.schildbach.pte.dto.Product;
|
|||
public class VbbProvider extends AbstractHafasProvider
|
||||
{
|
||||
private static final String API_BASE = "http://fahrinfo.vbb.de/bin/";
|
||||
private static final Set<Product> ALL_EXCEPT_HIGHSPEED_AND_ONDEMAND = EnumSet.complementOf(EnumSet
|
||||
.of(Product.HIGH_SPEED_TRAIN, Product.ON_DEMAND));
|
||||
private static final Product[] PRODUCTS_MAP = { Product.SUBURBAN_TRAIN, Product.SUBWAY, Product.TRAM, Product.BUS, Product.FERRY,
|
||||
Product.HIGH_SPEED_TRAIN, Product.REGIONAL_TRAIN };
|
||||
private static final Set<Product> ALL_EXCEPT_HIGHSPEED_AND_ONDEMAND = EnumSet
|
||||
.complementOf(EnumSet.of(Product.HIGH_SPEED_TRAIN, Product.ON_DEMAND));
|
||||
|
||||
public VbbProvider()
|
||||
{
|
||||
super(NetworkId.VBB, API_BASE + "stboard.exe/dn", API_BASE + "ajax-getstop.exe/dn", API_BASE + "query.exe/dn", 7, Charsets.UTF_8);
|
||||
super(NetworkId.VBB, API_BASE + "stboard.exe/dn", API_BASE + "ajax-getstop.exe/dn", API_BASE + "query.exe/dn", PRODUCTS_MAP, Charsets.UTF_8);
|
||||
|
||||
setJsonGetStopsUseWeight(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Product intToProduct(final int value)
|
||||
{
|
||||
if (value == 1)
|
||||
return Product.SUBURBAN_TRAIN;
|
||||
if (value == 2)
|
||||
return Product.SUBWAY;
|
||||
if (value == 4)
|
||||
return Product.TRAM;
|
||||
if (value == 8)
|
||||
return Product.BUS;
|
||||
if (value == 16)
|
||||
return Product.FERRY;
|
||||
if (value == 32)
|
||||
return Product.HIGH_SPEED_TRAIN;
|
||||
if (value == 64)
|
||||
return Product.REGIONAL_TRAIN;
|
||||
|
||||
throw new IllegalArgumentException("cannot handle: " + value);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setProductBits(final StringBuilder productBits, final Product product)
|
||||
{
|
||||
if (product == Product.HIGH_SPEED_TRAIN)
|
||||
{
|
||||
productBits.setCharAt(5, '1');
|
||||
}
|
||||
else if (product == Product.REGIONAL_TRAIN)
|
||||
{
|
||||
productBits.setCharAt(6, '1');
|
||||
}
|
||||
else if (product == Product.SUBURBAN_TRAIN)
|
||||
{
|
||||
productBits.setCharAt(0, '1');
|
||||
}
|
||||
else if (product == Product.SUBWAY)
|
||||
{
|
||||
productBits.setCharAt(1, '1');
|
||||
}
|
||||
else if (product == Product.TRAM)
|
||||
{
|
||||
productBits.setCharAt(2, '1');
|
||||
}
|
||||
else if (product == Product.BUS || product == Product.ON_DEMAND)
|
||||
{
|
||||
productBits.setCharAt(3, '1');
|
||||
}
|
||||
else if (product == Product.FERRY)
|
||||
{
|
||||
productBits.setCharAt(4, '1');
|
||||
}
|
||||
else if (product == Product.CABLECAR)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalArgumentException("cannot handle: " + product);
|
||||
}
|
||||
}
|
||||
|
||||
private static final Pattern P_SPLIT_NAME_SU = Pattern.compile("(.*?)(?:\\s+\\((S|U|S\\+U)\\))?");
|
||||
private static final Pattern P_SPLIT_NAME_BUS = Pattern.compile("(.*?)(\\s+\\[[^\\]]+\\])?");
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue