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.java116
1 files changed, 106 insertions, 10 deletions
diff --git a/src/net/cbaines/suma/BusRoute.java b/src/net/cbaines/suma/BusRoute.java
index cdb0e4d..244f56e 100644
--- a/src/net/cbaines/suma/BusRoute.java
+++ b/src/net/cbaines/suma/BusRoute.java
@@ -160,7 +160,7 @@ public class BusRoute {
ArrayList<Integer> stopIndexs = new ArrayList<Integer>();
for (RouteStops routeStop : routeStopsFound) {
- if (routeStop.stop.id.equals(busStop.id)) {
+ if (routeStop.busStop.id.equals(busStop.id)) {
stopIndexs.add(routeStop.sequence - 1);
}
}
@@ -175,7 +175,7 @@ public class BusRoute {
stopWanted = stopWanted % (routeStopsFound.size() - 1);
}
Log.v(TAG, " Stop wanted " + stopWanted);
- BusStop busStopWanted = routeStopsFound.get(stopWanted).stop;
+ BusStop busStopWanted = routeStopsFound.get(stopWanted).busStop;
busStopDao.refresh(busStopWanted);
@@ -189,12 +189,12 @@ public class BusRoute {
stopWanted = routeStopsFound.size() - (Math.abs(stopWanted) % routeStopsFound.size());
}
Log.v(TAG, "stopWanted " + stopWanted);
- busStopDao.refresh(routeStopsFound.get(stopWanted).stop);
+ busStopDao.refresh(routeStopsFound.get(stopWanted).busStop);
- Log.v(TAG, "Moving backwards " + moveAmount + " stops from " + busStop + " to " + routeStopsFound.get(stopWanted).stop + " in route "
+ Log.v(TAG, "Moving backwards " + moveAmount + " stops from " + busStop + " to " + routeStopsFound.get(stopWanted).busStop + " in route "
+ this);
- busStops.add(routeStopsFound.get(stopWanted).stop);
+ busStops.add(routeStopsFound.get(stopWanted).busStop);
}
}
@@ -246,7 +246,7 @@ public class BusRoute {
int stopIndex = -1;
for (RouteStops routeStop : routeStopsFound) {
- if (routeStop.stop.id.equals(busStop.id)) {
+ if (routeStop.busStop.id.equals(busStop.id)) {
if (stopIndex == -1) {
stopIndex = routeStop.sequence - 1;
} else { // ARGH, weird route
@@ -333,7 +333,7 @@ public class BusRoute {
stopWanted = stopWanted % (routeStopsFound.size() - 1);
}
Log.v(TAG, " Stop wanted " + stopWanted);
- BusStop busStopWanted = routeStopsFound.get(stopWanted).stop;
+ BusStop busStopWanted = routeStopsFound.get(stopWanted).busStop;
busStopDao.refresh(busStopWanted);
@@ -347,11 +347,11 @@ public class BusRoute {
stopWanted = routeStopsFound.size() - (Math.abs(stopWanted) % routeStopsFound.size());
}
Log.v(TAG, "stopWanted " + stopWanted);
- busStopDao.refresh(routeStopsFound.get(stopWanted).stop);
+ busStopDao.refresh(routeStopsFound.get(stopWanted).busStop);
- Log.v(TAG, "Moving backwards " + moveAmount + " stops from " + busStop + " to " + routeStopsFound.get(stopWanted).stop + " in route " + this);
+ Log.v(TAG, "Moving backwards " + moveAmount + " stops from " + busStop + " to " + routeStopsFound.get(stopWanted).busStop + " in route " + this);
- return routeStopsFound.get(stopWanted).stop;
+ return routeStopsFound.get(stopWanted).busStop;
}
} catch (SQLException e) {
@@ -361,6 +361,102 @@ public class BusRoute {
return null;
}
+ /**
+ * Untested?
+ *
+ * @param context
+ * @param busStop
+ * @param moveAmount
+ * @return
+ */
+ List<BusStop> getRouteSection(final Context context, String direction) {
+
+ DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class);
+
+ if (forwardDirection != null) {
+
+ if (direction != null) {
+
+ if (direction.equals("E"))
+ direction = "A"; // Quick hack for U1E
+ } else {
+ throw new NullPointerException("direction is null");
+ }
+ }
+
+ List<BusStop> busStops = new ArrayList<BusStop>();
+
+ try {
+
+ Dao<RouteStops, Integer> routeStopsDao = helper.getRouteStopsDao();
+ Dao<BusStop, String> busStopDao = helper.getBusStopDao();
+
+ QueryBuilder<RouteStops, Integer> routeStopsQueryBuilder = routeStopsDao.queryBuilder();
+ routeStopsQueryBuilder.where().eq(RouteStops.ROUTE_ID_FIELD_NAME, this.id);
+ PreparedQuery<RouteStops> routeStopsPreparedQuery = routeStopsQueryBuilder.prepare();
+
+ List<RouteStops> routeStopsFound = routeStopsDao.query(routeStopsPreparedQuery);
+
+ int startStopSeq = -1;
+ int endStopSeq = -1;
+
+ if (id == 326) { // U1
+ if (direction.equals(forwardDirection)) {
+ startStopSeq = 1;
+ endStopSeq = 43;
+ } else if (direction.equals(reverseDirection)) {
+ startStopSeq = 44;
+ endStopSeq = 88;
+ } else {
+ Log.e(TAG, "Error, unrecognised direction " + direction);
+ }
+ } else if (id == 468) { // U1N
+ startStopSeq = 1;
+ endStopSeq = 29;
+ } else if (id == 329) { // U2
+ if (direction.equals(forwardDirection)) {
+ startStopSeq = 1;
+ endStopSeq = 22;
+ } else if (direction.equals(reverseDirection)) {
+ startStopSeq = 23;
+ endStopSeq = 43;
+ } else {
+ Log.e(TAG, "Error, unrecognised direction " + direction);
+ }
+ } else if (id == 327) { // U6
+ if (direction.equals(forwardDirection)) {
+ startStopSeq = 1;
+ endStopSeq = 44;
+ } else if (direction.equals(reverseDirection)) {
+ startStopSeq = 45;
+ endStopSeq = 93;
+ } else {
+ Log.e(TAG, "Error, unrecognised direction " + direction);
+ }
+ } else if (id == 354) { // U9
+ startStopSeq = 1;
+ endStopSeq = 74;
+ } else {
+ Log.e(TAG, "Error, unrecognised route " + id);
+ }
+
+ for (RouteStops routeStop : routeStopsFound) {
+ if (routeStop.sequence >= startStopSeq && routeStop.sequence <= endStopSeq) {
+ busStopDao.refresh(routeStop.busStop);
+ busStops.add(routeStop.busStop);
+ }
+ }
+
+ return busStops;
+
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ Log.e(TAG, "Error moving in route");
+ return null;
+
+ }
+
@Override
public int hashCode() {
final int prime = 31;