diff options
author | Christopher Baines <cbaines8@gmail.com> | 2012-02-28 19:09:23 +0000 |
---|---|---|
committer | Christopher Baines <cbaines8@gmail.com> | 2012-02-28 19:09:23 +0000 |
commit | 0b5aefbe0ff01638dd264222c5368ad02a0fe1ee (patch) | |
tree | 2e6fdbd38ce7d97b757dcf365fe72aac7a163ddb /src/net/cbaines/suma/BusRoute.java | |
parent | ed7638698d439d75ada5120121a137f8e6f09bf8 (diff) | |
download | southamptonuniversitymap-0b5aefbe0ff01638dd264222c5368ad02a0fe1ee.tar southamptonuniversitymap-0b5aefbe0ff01638dd264222c5368ad02a0fe1ee.tar.gz |
Fixed two bugs relating to the query on the database not being ordered?, and implemented a new preference option.
Diffstat (limited to 'src/net/cbaines/suma/BusRoute.java')
-rw-r--r-- | src/net/cbaines/suma/BusRoute.java | 74 |
1 files changed, 38 insertions, 36 deletions
diff --git a/src/net/cbaines/suma/BusRoute.java b/src/net/cbaines/suma/BusRoute.java index b4dd603..ff80c66 100644 --- a/src/net/cbaines/suma/BusRoute.java +++ b/src/net/cbaines/suma/BusRoute.java @@ -22,6 +22,7 @@ package net.cbaines.suma; import java.sql.SQLException; import java.util.ArrayList; import java.util.Calendar; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -64,8 +65,7 @@ public class BusRoute { String label; /** - * The direction the bus is travelling if it is moving through the route and - * sequence is increasing. + * The direction the bus is travelling if it is moving through the route and sequence is increasing. * <ul> * <li>U1 = A</li> * <li>U2 = B</li> @@ -76,8 +76,7 @@ public class BusRoute { String forwardDirection; /** - * The direction the bus is travelling if it is moving through the route and - * sequence is decreasing. + * The direction the bus is travelling if it is moving through the route and sequence is decreasing. * <ul> * <li>U1 = C</li> * <li>U2 = C</li> @@ -93,8 +92,7 @@ public class BusRoute { BusRoute() { } - public BusRoute(Integer id, String code, String label, String forwardDirection, String reverseDirection, - boolean uniLink) { + public BusRoute(Integer id, String code, String label, String forwardDirection, String reverseDirection, boolean uniLink) { this.id = id.intValue(); this.code = code; this.label = label; @@ -153,18 +151,19 @@ public class BusRoute { DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class); try { - Dao<RouteStops, Integer> routeStopsDao = helper.getRouteStopsDao(); + Dao<RouteStop, 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(); + QueryBuilder<RouteStop, Integer> routeStopsQueryBuilder = routeStopsDao.queryBuilder(); + routeStopsQueryBuilder.where().eq(RouteStop.ROUTE_ID_FIELD_NAME, this.id); + PreparedQuery<RouteStop> routeStopsPreparedQuery = routeStopsQueryBuilder.prepare(); - List<RouteStops> routeStopsFound = routeStopsDao.query(routeStopsPreparedQuery); + List<RouteStop> routeStopsFound = routeStopsDao.query(routeStopsPreparedQuery); + Collections.sort(routeStopsFound); - ArrayList<Integer> stopIndexs = new ArrayList<Integer>(); + Set<Integer> stopIndexs = new HashSet<Integer>(); - for (RouteStops routeStop : routeStopsFound) { + for (RouteStop routeStop : routeStopsFound) { if (routeStop.busStop.id.equals(busStop.id)) { stopIndexs.add(routeStop.sequence - 1); } @@ -241,18 +240,19 @@ public class BusRoute { } try { - Dao<RouteStops, Integer> routeStopsDao = helper.getRouteStopsDao(); + Dao<RouteStop, 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(); + QueryBuilder<RouteStop, Integer> routeStopsQueryBuilder = routeStopsDao.queryBuilder(); + routeStopsQueryBuilder.where().eq(RouteStop.ROUTE_ID_FIELD_NAME, this.id); + PreparedQuery<RouteStop> routeStopsPreparedQuery = routeStopsQueryBuilder.prepare(); - List<RouteStops> routeStopsFound = routeStopsDao.query(routeStopsPreparedQuery); + List<RouteStop> routeStopsFound = routeStopsDao.query(routeStopsPreparedQuery); + Collections.sort(routeStopsFound); int stopIndex = -1; - for (RouteStops routeStop : routeStopsFound) { + for (RouteStop routeStop : routeStopsFound) { if (routeStop.busStop.id.equals(busStop.id)) { if (stopIndex == -1) { stopIndex = routeStop.sequence - 1; @@ -377,8 +377,9 @@ public class BusRoute { } if (moveAmount > 0) { - Log.v(TAG, "Moving forward " + moveAmount + " stops from " + busStop + " (" + stopIndex + "/" - + routeStopsFound.size() + ")"); + 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"); @@ -401,9 +402,8 @@ public class BusRoute { Log.v(TAG, "stopWanted " + stopWanted); busStopDao.refresh(routeStopsFound.get(stopWanted).busStop); - Log.v(TAG, - "Moving backwards " + moveAmount + " stops from " + busStop + " to " - + routeStopsFound.get(stopWanted).busStop + " in route " + this); + Log.v(TAG, "Moving backwards " + moveAmount + " stops from " + busStop + " to " + + routeStopsFound.get(stopWanted).busStop + " in route " + this); return routeStopsFound.get(stopWanted).busStop; } @@ -442,14 +442,15 @@ public class BusRoute { try { - Dao<RouteStops, Integer> routeStopsDao = helper.getRouteStopsDao(); + Dao<RouteStop, 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(); + QueryBuilder<RouteStop, Integer> routeStopsQueryBuilder = routeStopsDao.queryBuilder(); + routeStopsQueryBuilder.where().eq(RouteStop.ROUTE_ID_FIELD_NAME, this.id); + PreparedQuery<RouteStop> routeStopsPreparedQuery = routeStopsQueryBuilder.prepare(); - List<RouteStops> routeStopsFound = routeStopsDao.query(routeStopsPreparedQuery); + List<RouteStop> routeStopsFound = routeStopsDao.query(routeStopsPreparedQuery); + Collections.sort(routeStopsFound); int startStopSeq = -1; int endStopSeq = -1; @@ -500,7 +501,7 @@ public class BusRoute { Log.e(TAG, "Error, unrecognised route " + id); } - for (RouteStops routeStop : routeStopsFound) { + for (RouteStop routeStop : routeStopsFound) { if (routeStop.sequence >= startStopSeq && routeStop.sequence <= endStopSeq) { busStopDao.refresh(routeStop.busStop); busStops.add(routeStop.busStop); @@ -525,16 +526,17 @@ public class BusRoute { try { - Dao<RouteStops, Integer> routeStopsDao = helper.getRouteStopsDao(); + Dao<RouteStop, 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(); + QueryBuilder<RouteStop, Integer> routeStopsQueryBuilder = routeStopsDao.queryBuilder(); + routeStopsQueryBuilder.where().eq(RouteStop.ROUTE_ID_FIELD_NAME, this.id); + PreparedQuery<RouteStop> routeStopsPreparedQuery = routeStopsQueryBuilder.prepare(); - List<RouteStops> routeStopsFound = routeStopsDao.query(routeStopsPreparedQuery); + List<RouteStop> routeStopsFound = routeStopsDao.query(routeStopsPreparedQuery); + Collections.sort(routeStopsFound); - for (RouteStops routeStop : routeStopsFound) { + for (RouteStop routeStop : routeStopsFound) { busStopDao.refresh(routeStop.busStop); busStops.add(routeStop.busStop); } |