From 1c077d6009d423bf2bb0836ccf7bcd387888bc99 Mon Sep 17 00:00:00 2001 From: Andreas Schildbach Date: Sat, 17 Nov 2018 14:27:05 +0100 Subject: [PATCH] Station: Take location products into account when determining relevant product. --- .../de/schildbach/oeffi/stations/Station.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/oeffi/src/de/schildbach/oeffi/stations/Station.java b/oeffi/src/de/schildbach/oeffi/stations/Station.java index 46314a8..b4cfb91 100644 --- a/oeffi/src/de/schildbach/oeffi/stations/Station.java +++ b/oeffi/src/de/schildbach/oeffi/stations/Station.java @@ -20,6 +20,7 @@ package de.schildbach.oeffi.stations; import static com.google.common.base.Preconditions.checkNotNull; import java.util.Date; +import java.util.EnumSet; import java.util.List; import javax.annotation.Nullable; @@ -46,12 +47,12 @@ public class Station { public Station(final NetworkId network, final Location location) { this.network = network; - this.location = location; + this.location = checkNotNull(location); } public Station(final NetworkId network, final Location location, final List lines) { this.network = network; - this.location = location; + this.location = checkNotNull(location); setLines(lines); } @@ -75,16 +76,20 @@ public class Station { if (relevantProduct != null) return relevantProduct; + // collect all products + final EnumSet products = EnumSet.noneOf(Product.class); + if (location.products != null) + products.addAll(location.products); + final List lines = this.lines; if (lines != null) { - for (final LineDestination line : checkNotNull(lines)) { + for (final LineDestination line : lines) { final Product product = line.line.product; - if (product != null) { - if (relevantProduct == null || product.ordinal() < checkNotNull(relevantProduct).ordinal()) - relevantProduct = product; - } + if (product != null) + products.add(product); } } + relevantProduct = !products.isEmpty() ? products.iterator().next() : null; return relevantProduct; }