Do not add duplicates

This commit is contained in:
PavelRatushny 2017-12-15 10:33:31 +02:00
parent bb62e054e8
commit 14dc6f90cf
2 changed files with 38 additions and 16 deletions

View file

@ -227,15 +227,26 @@ public class AmenityMenuController extends MenuController {
Collection<TransportRoute> rts = t.getRouteForStop(s);
if (rts != null) {
for (TransportRoute rs : rts) {
TransportStopController.TransportStopType type = TransportStopController.TransportStopType.findType(rs.getType());
TransportStopRoute r = new TransportStopRoute();
r.type = type;
r.desc = useEnglishNames ? rs.getEnName(true) : rs.getName();
r.route = rs;
r.stop = s;
r.distance = dist;
this.routes.add(r);
if (!containsRef(rs)) {
TransportStopController.TransportStopType type = TransportStopController.TransportStopType.findType(rs.getType());
TransportStopRoute r = new TransportStopRoute();
r.type = type;
r.desc = useEnglishNames ? rs.getEnName(true) : rs.getName();
r.route = rs;
r.stop = s;
r.distance = dist;
this.routes.add(r);
}
}
}
}
private boolean containsRef(TransportRoute transportRoute) {
for (TransportStopRoute route : routes) {
if (route.route.getRef().equals(transportRoute.getRef())) {
return true;
}
}
return false;
}
}

View file

@ -201,21 +201,32 @@ public class TransportStopController extends MenuController {
if (rts != null) {
for (TransportRoute rs : rts) {
TransportStopType type = TransportStopType.findType(rs.getType());
TransportStopRoute r = new TransportStopRoute();
if (topType == null && type != null && type.isTopType()) {
topType = type;
}
r.type = type;
r.desc = useEnglishNames ? rs.getEnName(true) : rs.getName();
r.route = rs;
r.refStop = refStop;
r.stop = s;
r.distance = dist;
this.routes.add(r);
if (!containsRef(rs)) {
TransportStopRoute r = new TransportStopRoute();
r.type = type;
r.desc = useEnglishNames ? rs.getEnName(true) : rs.getName();
r.route = rs;
r.refStop = refStop;
r.stop = s;
r.distance = dist;
this.routes.add(r);
}
}
}
}
private boolean containsRef(TransportRoute transportRoute) {
for (TransportStopRoute route : routes) {
if (route.route.getRef().equals(transportRoute.getRef())) {
return true;
}
}
return false;
}
public static class TransportStopRoute {
public TransportStop refStop;
public TransportStopType type;