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.java42
1 files changed, 23 insertions, 19 deletions
diff --git a/src/net/cbaines/suma/BusRoute.java b/src/net/cbaines/suma/BusRoute.java
index ff80c66..e57e49c 100644
--- a/src/net/cbaines/suma/BusRoute.java
+++ b/src/net/cbaines/suma/BusRoute.java
@@ -65,7 +65,8 @@ 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,7 +77,8 @@ 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>
@@ -92,7 +94,8 @@ 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;
@@ -132,7 +135,8 @@ public class BusRoute {
}
/**
- * Untested?
+ * Return the set of bus stops that can be thought of moveAmount away from
+ * the busStop. The method returns a set as
*
* @param context
* @param busStop
@@ -165,7 +169,7 @@ public class BusRoute {
for (RouteStop routeStop : routeStopsFound) {
if (routeStop.busStop.id.equals(busStop.id)) {
- stopIndexs.add(routeStop.sequence - 1);
+ stopIndexs.add(routeStop.sequence);
}
}
@@ -174,24 +178,24 @@ public class BusRoute {
if (moveAmount > 0) {
Log.v(TAG, "Moving forward " + moveAmount + " stops from " + busStop + " (" + stopIndex + "/"
+ routeStopsFound.size() + ")");
- int stopWanted = stopIndex + moveAmount;
- if ((stopWanted + 1) > routeStopsFound.size()) {
+ int stopWantedSeq = stopIndex + moveAmount;
+ if (stopWantedSeq > routeStopsFound.size()) {
Log.v(TAG, "Off the end of the route");
- stopWanted = stopWanted % (routeStopsFound.size() - 1);
+ stopWantedSeq = ((stopWantedSeq - 1) % (routeStopsFound.size())) + 1;
}
- Log.v(TAG, " Stop wanted " + stopWanted);
- BusStop busStopWanted = routeStopsFound.get(stopWanted).busStop;
+ Log.v(TAG, " Stop wanted " + stopWantedSeq);
+ BusStop busStopWanted = routeStopsFound.get(stopWantedSeq - 1).busStop;
busStopDao.refresh(busStopWanted);
- Log.v(TAG, " Moving to " + busStopWanted + " (" + stopWanted + ") in route " + this);
+ Log.v(TAG, " Moving to " + busStopWanted + " (" + stopWantedSeq + ") 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());
+ if (stopWanted < 1) {
+ stopWanted = routeStopsFound.size() - (Math.abs(stopWanted - 1) % routeStopsFound.size());
}
Log.v(TAG, "stopWanted " + stopWanted);
busStopDao.refresh(routeStopsFound.get(stopWanted).busStop);
@@ -377,11 +381,10 @@ 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()) {
+ if (stopWanted > routeStopsFound.size()) {
Log.v(TAG, "Off the end of the route");
stopWanted = stopWanted % (routeStopsFound.size() - 1);
}
@@ -402,8 +405,9 @@ 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;
}