aboutsummaryrefslogtreecommitdiff
path: root/src/net/cbaines
diff options
context:
space:
mode:
authorChristopher Baines <cbaines8@gmail.com>2012-02-17 14:15:03 +0000
committerChristopher Baines <cbaines8@gmail.com>2012-02-17 14:15:03 +0000
commitfdc65e639563d145b042f9fa3d8be5b27efce8e2 (patch)
tree5f317d0bb791254ae5a7cd88917c314bb7b457fc /src/net/cbaines
parent3f10264e8dba0cd972647fbe1379f148b1ee6847 (diff)
downloadsouthamptonuniversitymap-fdc65e639563d145b042f9fa3d8be5b27efce8e2.tar
southamptonuniversitymap-fdc65e639563d145b042f9fa3d8be5b27efce8e2.tar.gz
Some changes?
Diffstat (limited to 'src/net/cbaines')
-rw-r--r--src/net/cbaines/suma/BusRoute.java87
-rw-r--r--src/net/cbaines/suma/SouthamptonUniversityMapActivity.java6
2 files changed, 86 insertions, 7 deletions
diff --git a/src/net/cbaines/suma/BusRoute.java b/src/net/cbaines/suma/BusRoute.java
index 94e8e37..ed6deeb 100644
--- a/src/net/cbaines/suma/BusRoute.java
+++ b/src/net/cbaines/suma/BusRoute.java
@@ -20,7 +20,10 @@
package net.cbaines.suma;
import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import android.content.Context;
import android.util.Log;
@@ -117,7 +120,87 @@ public class BusRoute {
* @param moveAmount
* @return
*/
- BusStop moveInRoute(final Context context, final BusStop busStop, String direction, int moveAmount) {
+ Set<BusStop> moveInRoute(final Context context, final BusStop busStop, final int moveAmount) {
+
+ if (!code.startsWith("U") || code.equals("U9")) {
+ throw new RuntimeException("Route Movement not supported for " + code);
+ }
+
+ Set<BusStop> busStops = new HashSet<BusStop>();
+
+ if (moveAmount == 0) {
+ busStops.add(busStop);
+ return busStops;
+ }
+
+ DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class);
+
+ 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);
+
+ ArrayList<Integer> stopIndexs = new ArrayList<Integer>();
+
+ for (RouteStops routeStop : routeStopsFound) {
+ if (routeStop.stop.id.equals(busStop.id)) {
+ stopIndexs.add(routeStop.sequence - 1);
+ }
+ }
+
+ for (int stopIndex : stopIndexs) {
+
+ if (moveAmount > 0) {
+ Log.v(TAG, "Moving forward " + 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);
+ BusStop busStopWanted = routeStopsFound.get(stopWanted).stop;
+
+ busStopDao.refresh(busStopWanted);
+
+ Log.v(TAG, " Moving to " + busStopWanted + " (" + stopWanted + ") in route " + this);
+
+ busStops.add(busStopWanted);
+ } else {
+ Log.v(TAG, "stopIndex " + stopIndex);
+ int stopWanted = stopIndex + moveAmount;
+ if (stopWanted < 0) {
+ stopWanted = routeStopsFound.size() - (Math.abs(stopWanted) % routeStopsFound.size());
+ }
+ Log.v(TAG, "stopWanted " + stopWanted);
+ busStopDao.refresh(routeStopsFound.get(stopWanted).stop);
+
+ Log.v(TAG, "Moving backwards " + moveAmount + " stops from " + busStop + " to " + routeStopsFound.get(stopWanted).stop + " in route "
+ + this);
+
+ busStops.add(routeStopsFound.get(stopWanted).stop);
+ }
+ }
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ Log.e(TAG, "Error moving in route");
+ return null;
+ }
+
+ /**
+ * Untested?
+ *
+ * @param context
+ * @param busStop
+ * @param moveAmount
+ * @return
+ */
+ BusStop moveInRoute(final Context context, final BusStop busStop, String direction, final int moveAmount) {
if (!code.startsWith("U") || code.equals("U9")) {
throw new RuntimeException("Route Movement not supported for " + code);
@@ -135,6 +218,8 @@ public class BusRoute {
if (direction.equals("E"))
direction = "A"; // Quick hack for U1E
+ } else {
+ throw new NullPointerException("direction is null");
}
}
diff --git a/src/net/cbaines/suma/SouthamptonUniversityMapActivity.java b/src/net/cbaines/suma/SouthamptonUniversityMapActivity.java
index d4754a4..26996a0 100644
--- a/src/net/cbaines/suma/SouthamptonUniversityMapActivity.java
+++ b/src/net/cbaines/suma/SouthamptonUniversityMapActivity.java
@@ -384,12 +384,6 @@ public class SouthamptonUniversityMapActivity extends OrmLiteBaseActivity<Databa
Log.i(TAG, "Begining setting up the static values " + (System.currentTimeMillis() - startTime));
- try {
- DataManager.routeMovementTest(this);
- } catch (SQLException e) {
- e.printStackTrace();
- }
-
Log.i(TAG, "Finished the database thread " + (System.currentTimeMillis() - startTime));
}