aboutsummaryrefslogtreecommitdiff
path: root/src/net/cbaines
diff options
context:
space:
mode:
authorChristopher Baines <cbaines8@gmail.com>2012-03-01 18:12:21 +0000
committerChristopher Baines <cbaines8@gmail.com>2012-03-01 18:12:21 +0000
commit8e2005fa2650b142b89799249b07ea72bdbcc906 (patch)
tree8a9f651b5a4781fdf35985400562a0a416a26bd5 /src/net/cbaines
parent7125dc4757c29dfe9f451e51078ff59ce1521a6c (diff)
downloadsouthamptonuniversitymap-8e2005fa2650b142b89799249b07ea72bdbcc906.tar
southamptonuniversitymap-8e2005fa2650b142b89799249b07ea72bdbcc906.tar.gz
Fixed route movement, now tested.
Diffstat (limited to 'src/net/cbaines')
-rw-r--r--src/net/cbaines/suma/BusRoute.java38
1 files changed, 18 insertions, 20 deletions
diff --git a/src/net/cbaines/suma/BusRoute.java b/src/net/cbaines/suma/BusRoute.java
index e57e49c..793cc24 100644
--- a/src/net/cbaines/suma/BusRoute.java
+++ b/src/net/cbaines/suma/BusRoute.java
@@ -65,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>
@@ -77,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>
@@ -94,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;
@@ -135,8 +132,8 @@ public class BusRoute {
}
/**
- * Return the set of bus stops that can be thought of moveAmount away from
- * the busStop. The method returns a set as
+ * Return the set of bus stops that can be thought of moveAmount away from the busStop. The method returns a set as for some
+ * movements, the destination stop is ambiguous.
*
* @param context
* @param busStop
@@ -165,6 +162,7 @@ public class BusRoute {
List<RouteStop> routeStopsFound = routeStopsDao.query(routeStopsPreparedQuery);
Collections.sort(routeStopsFound);
+ // Starting from 1, as the data does :(
Set<Integer> stopIndexs = new HashSet<Integer>();
for (RouteStop routeStop : routeStopsFound) {
@@ -193,18 +191,18 @@ public class BusRoute {
busStops.add(busStopWanted);
} else {
Log.v(TAG, "stopIndex " + stopIndex);
- int stopWanted = stopIndex + moveAmount;
+ int stopWanted = stopIndex + moveAmount; // This will end up as the sequence number of the wanted stop
if (stopWanted < 1) {
- stopWanted = routeStopsFound.size() - (Math.abs(stopWanted - 1) % routeStopsFound.size());
+ stopWanted = routeStopsFound.size() - (Math.abs(stopWanted) % routeStopsFound.size());
}
Log.v(TAG, "stopWanted " + stopWanted);
- busStopDao.refresh(routeStopsFound.get(stopWanted).busStop);
+ BusStop wantedBusStop = routeStopsFound.get(stopWanted - 1).busStop; // Need the -1 as sequence starts at 1
+ busStopDao.refresh(wantedBusStop);
- Log.v(TAG,
- "Moving backwards " + moveAmount + " stops from " + busStop + " to "
- + routeStopsFound.get(stopWanted).busStop + " in route " + this);
+ Log.v(TAG, "Moving backwards " + (-1 * moveAmount) + " stops from " + busStop + " to " + wantedBusStop
+ + " in route " + this);
- busStops.add(routeStopsFound.get(stopWanted).busStop);
+ busStops.add(wantedBusStop);
}
}
@@ -381,8 +379,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 > routeStopsFound.size()) {
Log.v(TAG, "Off the end of the route");
@@ -405,9 +404,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;
}