diff options
Diffstat (limited to 'src/net/cbaines/suma/BusRoute.java')
-rw-r--r-- | src/net/cbaines/suma/BusRoute.java | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/src/net/cbaines/suma/BusRoute.java b/src/net/cbaines/suma/BusRoute.java index ff80c66..793cc24 100644 --- a/src/net/cbaines/suma/BusRoute.java +++ b/src/net/cbaines/suma/BusRoute.java @@ -132,7 +132,8 @@ public class BusRoute { } /** - * Untested? + * Return the set of bus stops that can be thought of moveAmount away from the busStop. The method returns a set as for some + * movements, the destination stop is ambiguous. * * @param context * @param busStop @@ -161,11 +162,12 @@ public class BusRoute { List<RouteStop> routeStopsFound = routeStopsDao.query(routeStopsPreparedQuery); Collections.sort(routeStopsFound); + // Starting from 1, as the data does :( Set<Integer> stopIndexs = new HashSet<Integer>(); for (RouteStop routeStop : routeStopsFound) { if (routeStop.busStop.id.equals(busStop.id)) { - stopIndexs.add(routeStop.sequence - 1); + stopIndexs.add(routeStop.sequence); } } @@ -174,33 +176,33 @@ public class BusRoute { if (moveAmount > 0) { Log.v(TAG, "Moving forward " + moveAmount + " stops from " + busStop + " (" + stopIndex + "/" + routeStopsFound.size() + ")"); - int stopWanted = stopIndex + moveAmount; - if ((stopWanted + 1) > routeStopsFound.size()) { + int stopWantedSeq = stopIndex + moveAmount; + if (stopWantedSeq > routeStopsFound.size()) { Log.v(TAG, "Off the end of the route"); - stopWanted = stopWanted % (routeStopsFound.size() - 1); + stopWantedSeq = ((stopWantedSeq - 1) % (routeStopsFound.size())) + 1; } - Log.v(TAG, " Stop wanted " + stopWanted); - BusStop busStopWanted = routeStopsFound.get(stopWanted).busStop; + Log.v(TAG, " Stop wanted " + stopWantedSeq); + BusStop busStopWanted = routeStopsFound.get(stopWantedSeq - 1).busStop; busStopDao.refresh(busStopWanted); - Log.v(TAG, " Moving to " + busStopWanted + " (" + stopWanted + ") in route " + this); + Log.v(TAG, " Moving to " + busStopWanted + " (" + stopWantedSeq + ") in route " + this); busStops.add(busStopWanted); } else { Log.v(TAG, "stopIndex " + stopIndex); - int stopWanted = stopIndex + moveAmount; - if (stopWanted < 0) { + int stopWanted = stopIndex + moveAmount; // This will end up as the sequence number of the wanted stop + if (stopWanted < 1) { stopWanted = routeStopsFound.size() - (Math.abs(stopWanted) % routeStopsFound.size()); } Log.v(TAG, "stopWanted " + stopWanted); - busStopDao.refresh(routeStopsFound.get(stopWanted).busStop); + BusStop wantedBusStop = routeStopsFound.get(stopWanted - 1).busStop; // Need the -1 as sequence starts at 1 + busStopDao.refresh(wantedBusStop); - Log.v(TAG, - "Moving backwards " + moveAmount + " stops from " + busStop + " to " - + routeStopsFound.get(stopWanted).busStop + " in route " + this); + Log.v(TAG, "Moving backwards " + (-1 * moveAmount) + " stops from " + busStop + " to " + wantedBusStop + + " in route " + this); - busStops.add(routeStopsFound.get(stopWanted).busStop); + busStops.add(wantedBusStop); } } @@ -381,7 +383,7 @@ public class BusRoute { "Moving forward " + moveAmount + " stops from " + busStop + " (" + stopIndex + "/" + routeStopsFound.size() + ")"); int stopWanted = stopIndex + moveAmount; - if ((stopWanted + 1) > routeStopsFound.size()) { + if (stopWanted > routeStopsFound.size()) { Log.v(TAG, "Off the end of the route"); stopWanted = stopWanted % (routeStopsFound.size() - 1); } |