aboutsummaryrefslogtreecommitdiff
path: root/src/net/cbaines/suma/BusRoute.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/cbaines/suma/BusRoute.java')
-rw-r--r--src/net/cbaines/suma/BusRoute.java114
1 files changed, 93 insertions, 21 deletions
diff --git a/src/net/cbaines/suma/BusRoute.java b/src/net/cbaines/suma/BusRoute.java
index 0101ae4..94e8e37 100644
--- a/src/net/cbaines/suma/BusRoute.java
+++ b/src/net/cbaines/suma/BusRoute.java
@@ -113,13 +113,18 @@ public class BusRoute {
* Untested?
*
* @param context
- * @param stop
+ * @param busStop
* @param moveAmount
* @return
*/
- BusStop moveInRoute(Context context, BusStop stop, String direction, int moveAmount) {
+ BusStop moveInRoute(final Context context, final BusStop busStop, String direction, int moveAmount) {
+
+ if (!code.startsWith("U") || code.equals("U9")) {
+ throw new RuntimeException("Route Movement not supported for " + code);
+ }
+
if (moveAmount == 0) {
- return stop;
+ return busStop;
}
DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class);
@@ -128,15 +133,8 @@ public class BusRoute {
if (direction != null) {
- if (forwardDirection.equals(direction)) {
-
- } else if (reverseDirection.equals(direction)) {
- moveAmount = -moveAmount;
- } else {
- Log.e("BusRoute", "Direction (" + direction + ") doesnt match either the forward direction (" + forwardDirection
- + ") or reverse direction (" + reverseDirection + ")");
- return null;
- }
+ if (direction.equals("E"))
+ direction = "A"; // Quick hack for U1E
}
}
@@ -150,29 +148,102 @@ public class BusRoute {
List<RouteStops> routeStopsFound = routeStopsDao.query(routeStopsPreparedQuery);
- int stopIndex = 0;
+ int stopIndex = -1;
for (RouteStops routeStop : routeStopsFound) {
- if (routeStop.stop.id.equals(stop.id)) {
- stopIndex = routeStop.sequence - 1;
+ if (routeStop.stop.id.equals(busStop.id)) {
+ if (stopIndex == -1) {
+ stopIndex = routeStop.sequence - 1;
+ } else { // ARGH, weird route
+ if (busStop.id.equals("HAA13651") && id == 327) { // U6 by Wessex Lane
+ if (direction.equals(forwardDirection)) {
+ stopIndex = 23;
+ } else {
+ stopIndex = 68;
+ }
+ } else if (busStop.id.equals("SN120134") && id == 327) { // U6 opposite the Stile
+ if (direction.equals(forwardDirection)) {
+ stopIndex = 30;
+ } else {
+ stopIndex = 59;
+ }
+ } else if (busStop.id.equals("SN120163") && id == 327) { // U6 just up past wessex lane
+ if (direction.equals(forwardDirection)) {
+ stopIndex = 22;
+ } else {
+ stopIndex = 67;
+ }
+ } else if (busStop.id.equals("SNA19482") && id == 327) { // U6 General Hosp West Door
+ if (moveAmount > 0) {
+ stopIndex = 44;
+ } else {
+ stopIndex = 43;
+ }
+ } else if (busStop.id.equals("SN120134") && id == 329) { // U2 opposite the Stile
+ if (direction.equals(forwardDirection)) {
+ stopIndex = 13;
+ } else {
+ stopIndex = 30;
+ }
+ } else if (busStop.id.equals("SN120527") && id == 329) { // U2 Civic Centre Rd os stop AO Civic Ctr E
+ if (moveAmount > 0) {
+ stopIndex = 0;
+ } else {
+ stopIndex = 42;
+ }
+ } else if (busStop.id.equals("SNA09298") && id == 329) { // U2 Bassett Green Rd nr Bassett Green Cl SE
+ if (moveAmount > 0) {
+ stopIndex = 22;
+ } else {
+ stopIndex = 21;
+ }
+ } else if (busStop.id.equals("SN120520") && id == 326) { // U1 By the station
+ if (direction.equals(forwardDirection)) {
+ stopIndex = 7;
+ } else {
+ stopIndex = 80;
+ }
+ } else if (busStop.id.equals("HA030183") && id == 326) { // U1 Up past Wessex Lane
+ if (direction.equals(forwardDirection)) {
+ stopIndex = 35;
+ } else {
+ stopIndex = 50;
+ }
+ } else if (busStop.id.equals("HA030212") && id == 326) { // U1 At Eastleigh
+ if (moveAmount > 0) {
+ stopIndex = 43;
+ } else {
+ stopIndex = 42;
+ }
+ } else if (busStop.id.equals("SN120171") && id == 354) { // U9
+ if (moveAmount > 0) {
+ stopIndex = 0;
+ } else {
+ stopIndex = 73;
+ }
+ } else {
+ Log.e(TAG, "Error, unknown bus stop " + busStop.id + " (" + busStop.description + ") that appears mutiple times in " + toString());
+ throw new RuntimeException("Error, unknown bus stop " + busStop.id + " that appears mutiple times in " + toString());
+ }
+ }
}
}
if (moveAmount > 0) {
Log.v(TAG,
- "Moving forward in direction " + direction + " " + moveAmount + " stops from " + stop + " (" + stopIndex + "/" + routeStopsFound.size()
- + ")");
+ "Moving forward in direction " + direction + " " + moveAmount + " stops from " + busStop + " (" + 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);
+ Log.v(TAG, " Stop wanted " + stopWanted);
BusStop busStopWanted = routeStopsFound.get(stopWanted).stop;
busStopDao.refresh(busStopWanted);
- Log.v(TAG, "Moving to " + busStopWanted + " (" + stopWanted + ") in route " + this);
+ Log.v(TAG, " Moving to " + busStopWanted + " (" + stopWanted + ") in route " + this);
return busStopWanted;
} else {
@@ -184,8 +255,9 @@ public class BusRoute {
Log.v(TAG, "stopWanted " + stopWanted);
busStopDao.refresh(routeStopsFound.get(stopWanted).stop);
- Log.v(TAG, "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 " + busStop + " to "
+ + routeStopsFound.get(stopWanted).stop + " in route " + this);
return routeStopsFound.get(stopWanted).stop;
}