diff options
author | Christopher Baines <cbaines8@gmail.com> | 2012-02-16 13:43:51 +0000 |
---|---|---|
committer | Christopher Baines <cbaines8@gmail.com> | 2012-02-16 13:43:51 +0000 |
commit | 86629c735d4f7c48e1562825ca63ba3335363cbb (patch) | |
tree | 87ff143b433350c531800428c6182e6568e44e9e /src/net/cbaines/suma/BusRoute.java | |
parent | e20303f3de0782c31a0a794d1be4a06e3b4a0c76 (diff) | |
download | southamptonuniversitymap-86629c735d4f7c48e1562825ca63ba3335363cbb.tar southamptonuniversitymap-86629c735d4f7c48e1562825ca63ba3335363cbb.tar.gz |
ARRRRRRRGHH, bus routes dont work, the U6 route loops over the same ground twice by wessex lane, traveling in the same direction, breaking the BusRoute.moveInRoute code :(
Diffstat (limited to 'src/net/cbaines/suma/BusRoute.java')
-rw-r--r-- | src/net/cbaines/suma/BusRoute.java | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/src/net/cbaines/suma/BusRoute.java b/src/net/cbaines/suma/BusRoute.java index 2dacfd2..0101ae4 100644 --- a/src/net/cbaines/suma/BusRoute.java +++ b/src/net/cbaines/suma/BusRoute.java @@ -41,6 +41,8 @@ import com.j256.ormlite.table.DatabaseTable; @DatabaseTable(tableName = "busroutes") public class BusRoute { + private static final String TAG = "BusRoute"; + final static String ID_FIELD_NAME = "id"; final static String CODE_FIELD_NAME = "code"; final static String LABEL_FIELD_NAME = "label"; @@ -147,7 +149,6 @@ public class BusRoute { PreparedQuery<RouteStops> routeStopsPreparedQuery = routeStopsQueryBuilder.prepare(); List<RouteStops> routeStopsFound = routeStopsDao.query(routeStopsPreparedQuery); - Log.v("BusRoute", "Found " + routeStopsFound.size() + " stops"); int stopIndex = 0; @@ -158,28 +159,33 @@ public class BusRoute { } if (moveAmount > 0) { - Log.v("BusStop", "stopIndex " + stopIndex); - int stopWanted = (stopIndex + moveAmount) % (routeStopsFound.size()); - Log.v("BusStop", "stopWanted " + stopWanted); - busStopDao.refresh(routeStopsFound.get(stopWanted).stop); + Log.v(TAG, + "Moving forward in direction " + direction + " " + moveAmount + " stops from " + stop + " (" + stopIndex + "/" + routeStopsFound.size() + + ")"); + int stopWanted = stopIndex + moveAmount; + if ((stopWanted + 1) > routeStopsFound.size()) { + Log.v(TAG, "Off the end of the route"); + stopWanted = stopWanted % (routeStopsFound.size() - 1); + } + Log.v(TAG, "Stop wanted " + stopWanted); + BusStop busStopWanted = routeStopsFound.get(stopWanted).stop; - Log.v("BusRoute", - "Moving forward in direction " + direction + " " + moveAmount + " stops from " + stop + " to " + routeStopsFound.get(stopWanted).stop - + " in route " + this); + busStopDao.refresh(busStopWanted); - return routeStopsFound.get(stopWanted).stop; + Log.v(TAG, "Moving to " + busStopWanted + " (" + stopWanted + ") in route " + this); + + return busStopWanted; } else { - Log.v("BusStop", "stopIndex " + stopIndex); + Log.v(TAG, "stopIndex " + stopIndex); int stopWanted = stopIndex + moveAmount; if (stopWanted < 0) { stopWanted = routeStopsFound.size() - (Math.abs(stopWanted) % routeStopsFound.size()); } - Log.v("BusStop", "stopWanted " + stopWanted); + Log.v(TAG, "stopWanted " + stopWanted); busStopDao.refresh(routeStopsFound.get(stopWanted).stop); - Log.v("BusRoute", - "Moving backwards in direction " + direction + " " + moveAmount + " stops from " + stop + " to " + routeStopsFound.get(stopWanted).stop - + " in route " + this); + Log.v(TAG, "Moving backwards in direction " + direction + " " + moveAmount + " stops from " + stop + " to " + + routeStopsFound.get(stopWanted).stop + " in route " + this); return routeStopsFound.get(stopWanted).stop; } @@ -187,7 +193,7 @@ public class BusRoute { } catch (SQLException e) { e.printStackTrace(); } - Log.e("BusRoute", "Error moving in route"); + Log.e(TAG, "Error moving in route"); return null; } |