diff --git a/enabler/src/de/schildbach/pte/AbstractHafasProvider.java b/enabler/src/de/schildbach/pte/AbstractHafasProvider.java index 8042a659..740b33f4 100644 --- a/enabler/src/de/schildbach/pte/AbstractHafasProvider.java +++ b/enabler/src/de/schildbach/pte/AbstractHafasProvider.java @@ -289,6 +289,26 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider return product; } + protected final Set intToProducts(int value) + { + final int allProductsInt = allProductsInt(); + checkArgument(value <= allProductsInt, "value " + value + " cannot be greater than " + allProductsInt); + + final Set products = EnumSet.noneOf(Product.class); + for (int i = productsMap.length - 1; i >= 0; i--) + { + final int v = 1 << i; + if (value >= v) + { + final Product product = checkNotNull(productsMap[i], "unknown product " + i); + products.add(product); + value -= v; + } + } + checkState(value == 0); + return products; + } + protected static final Pattern P_SPLIT_NAME_FIRST_COMMA = Pattern.compile("([^,]*), (.*)"); protected static final Pattern P_SPLIT_NAME_LAST_COMMA = Pattern.compile("(.*), ([^,]*)"); protected static final Pattern P_SPLIT_NAME_PAREN = Pattern.compile("(.*) \\((.{3,}?)\\)"); @@ -2481,12 +2501,14 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider final String urlname = ParserUtils.urlDecode(stop.getString("urlname"), jsonNearbyLocationsEncoding); final int lat = stop.getInt("y"); final int lon = stop.getInt("x"); + final int prodclass = stop.optInt("prodclass", -1); final int stopWeight = stop.optInt("stopweight", -1); if (stopWeight != 0) { final String[] placeAndName = splitStationName(urlname); - locations.add(new Location(LocationType.STATION, id, lat, lon, placeAndName[0], placeAndName[1])); + final Set products = prodclass != -1 ? intToProducts(prodclass) : null; + locations.add(new Location(LocationType.STATION, id, lat, lon, placeAndName[0], placeAndName[1], products)); } } } diff --git a/enabler/src/de/schildbach/pte/dto/Location.java b/enabler/src/de/schildbach/pte/dto/Location.java index 59aaea25..53dcd5ac 100644 --- a/enabler/src/de/schildbach/pte/dto/Location.java +++ b/enabler/src/de/schildbach/pte/dto/Location.java @@ -22,6 +22,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import java.io.Serializable; import java.util.Arrays; +import java.util.Set; import javax.annotation.Nullable; @@ -42,8 +43,10 @@ public final class Location implements Serializable public final int lat, lon; public final @Nullable String place; public final @Nullable String name; + public final @Nullable Set products; - public Location(final LocationType type, final String id, final int lat, final int lon, final String place, final String name) + public Location(final LocationType type, final String id, final int lat, final int lon, final String place, final String name, + final Set products) { this.type = checkNotNull(type); this.id = id; @@ -51,6 +54,7 @@ public final class Location implements Serializable this.lon = lon; this.place = place; this.name = name; + this.products = products; checkArgument(id == null || id.length() > 0, "ID cannot be the empty string"); checkArgument(place == null || name != null, "place '%s' without name cannot exist", place); @@ -61,6 +65,11 @@ public final class Location implements Serializable } } + public Location(final LocationType type, final String id, final int lat, final int lon, final String place, final String name) + { + this(type, id, lat, lon, place, name, null); + } + public Location(final LocationType type, final String id, final Point coord, final String place, final String name) { this(type, id, coord != null ? coord.lat : 0, coord != null ? coord.lon : 0, place, name); @@ -182,6 +191,6 @@ public final class Location implements Serializable final ToStringHelper helper = MoreObjects.toStringHelper(this).addValue(type).addValue(id); if (hasLocation()) helper.addValue(lat + "/" + lon); - return helper.add("place", place).add("name", name).omitNullValues().toString(); + return helper.add("place", place).add("name", name).add("products", products).omitNullValues().toString(); } }