BartRunnerAndroid/src/com/dougkeen/bart/model/Route.java

120 lines
2.9 KiB
Java
Raw Normal View History

package com.dougkeen.bart.model;
2011-05-23 18:59:34 +00:00
public class Route {
private Station origin;
private Station destination;
private Line line;
private boolean requiresTransfer;
private Station transferStation;
2011-05-23 18:59:34 +00:00
private String direction;
2012-01-02 23:08:43 +00:00
private String fare;
private Long fareLastUpdated;
2011-05-23 18:59:34 +00:00
public Station getOrigin() {
return origin;
}
public void setOrigin(Station origin) {
this.origin = origin;
}
public Station getDestination() {
return destination;
}
public void setDestination(Station destination) {
this.destination = destination;
}
public Line getLine() {
return line;
}
public void setLine(Line line) {
this.line = line;
}
public boolean hasTransfer() {
return requiresTransfer;
}
public void setTransfer(boolean requiresTransfer) {
this.requiresTransfer = requiresTransfer;
}
public Station getTransferStation() {
return transferStation;
}
public void setTransferStation(Station transferStation) {
this.transferStation = transferStation;
}
2011-05-23 18:59:34 +00:00
public String getDirection() {
return direction;
}
public void setDirection(String direction) {
this.direction = direction;
}
2012-01-02 23:08:43 +00:00
public String getFare() {
return fare;
}
public void setFare(String fare) {
this.fare = fare;
}
public Long getFareLastUpdated() {
return fareLastUpdated;
}
public void setFareLastUpdated(Long fareLastUpdated) {
this.fareLastUpdated = fareLastUpdated;
}
2011-05-23 18:59:34 +00:00
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("Route [origin=");
builder.append(origin);
builder.append(", destination=");
builder.append(destination);
builder.append(", line=");
builder.append(line);
builder.append(", requiresTransfer=");
builder.append(requiresTransfer);
builder.append(", transferStation=");
builder.append(transferStation);
2011-05-23 18:59:34 +00:00
builder.append(", direction=");
builder.append(direction);
2012-01-02 23:08:43 +00:00
builder.append(", fare=");
builder.append(fare);
builder.append(", fareLastUpdated=");
builder.append(fareLastUpdated);
2011-05-23 18:59:34 +00:00
builder.append("]");
return builder.toString();
}
2011-06-01 03:42:32 +00:00
public boolean trainDestinationIsApplicable(Station lineDestination,
Line viaLine) {
Line routeLine = getLine();
if (routeLine.transferLine1 != null
&& viaLine.equals(routeLine.transferLine1)) {
return true;
} else if (routeLine.transferLine2 != null
&& viaLine.equals(routeLine.transferLine2)) {
return true;
} else {
int originIndex = viaLine.stations.indexOf(origin);
int routeDestinationIndex = viaLine.stations.indexOf(destination);
int lineDestinationIndex = viaLine.stations
.indexOf(lineDestination);
return routeDestinationIndex >= 0
2012-01-02 23:08:43 +00:00
&& ((originIndex <= routeDestinationIndex && routeDestinationIndex <= lineDestinationIndex) || (originIndex >= routeDestinationIndex && routeDestinationIndex >= lineDestinationIndex));
2011-06-01 03:42:32 +00:00
}
}
2011-05-23 18:59:34 +00:00
}