2012-04-13 01:07:55 +00:00
|
|
|
package com.dougkeen.bart.model;
|
2011-05-23 18:59:34 +00:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2012-04-13 01:07:55 +00:00
|
|
|
import android.util.Log;
|
|
|
|
|
2011-05-23 18:59:34 +00:00
|
|
|
public enum Station {
|
2012-04-13 01:07:55 +00:00
|
|
|
_12TH("12th", "12th St./Oakland City Center", false, false, "bayf"), _16TH(
|
|
|
|
"16th", "16th St. Mission", false, false), _19TH("19th",
|
|
|
|
"19th St./Oakland", false, false, "bayf"), _24TH("24th",
|
|
|
|
"24th St. Mission", false, false), ASHB("ashb", "Ashby", false,
|
|
|
|
false, "mcar"), BALB("balb", "Balboa Park", false, false), BAYF(
|
|
|
|
"bayf", "Bay Fair", true, false, "mcar"), CAST("cast",
|
|
|
|
"Castro Valley", false, false, "bayf"), CIVC("civc",
|
|
|
|
"Civic Center", false, false), COLS("cols",
|
|
|
|
"Coliseum/Oakland Airport", true, false, "mcar"), COLM("colm",
|
|
|
|
"Colma", false, false, "balb", "balb"), CONC("conc", "Concord",
|
|
|
|
false, false, "mcar"), DALY("daly", "Daly City", false, false), DBRK(
|
|
|
|
"dbrk", "Downtown Berkeley", false, false, "mcar"), DUBL("dubl",
|
|
|
|
"Dublin/Pleasanton", false, true, "bayf"), DELN("deln",
|
|
|
|
"El Cerrito del Norte", false, false, "mcar"), PLZA("plza",
|
|
|
|
"El Cerrito Plaza", false, false, "mcar"), EMBR("embr",
|
|
|
|
"Embarcadero", false, false), FRMT("frmt", "Fremont", true, false,
|
|
|
|
"bayf"), FTVL("ftvl", "Fruitvale", true, false, "mcar"), GLEN(
|
|
|
|
"glen", "Glen Park", false, false), HAYW("hayw", "Hayward", true,
|
|
|
|
false, "bayf"), LAFY("lafy", "Lafayette", false, false, "mcar"), LAKE(
|
|
|
|
"lake", "Lake Merritt", true, false, "mcar"), MCAR("mcar",
|
|
|
|
"MacArthur", false, false, "bayf"), MLBR("mlbr", "Millbrae", false,
|
|
|
|
true, "balb", "balb"), MONT("mont", "Montgomery St.", false, false), NBRK(
|
|
|
|
"nbrk", "North Berkeley", false, false, "mcar"), NCON("ncon",
|
|
|
|
"North Concord/Martinez", false, false, "mcar"), ORIN("orin",
|
|
|
|
"Orinda", false, false, "mcar"), PITT("pitt",
|
|
|
|
"Pittsburg/Bay Point", false, true, "mcar"), PHIL("phil",
|
|
|
|
"Pleasant Hill", false, false, "mcar"), POWL("powl", "Powell St.",
|
|
|
|
false, false), RICH("rich", "Richmond", false, true, "mcar"), ROCK(
|
|
|
|
"rock", "Rockridge", false, false, "mcar"), SBRN("sbrn",
|
|
|
|
"San Bruno", false, false, "balb", "balb"), SANL("sanl",
|
|
|
|
"San Leandro", true, false, "mcar"), SFIA("sfia", "SFO Airport",
|
|
|
|
false, false, "sbrn", "balb"), SHAY("shay", "South Hayward", true,
|
|
|
|
false, "bayf"), SSAN("ssan", "South San Francisco", false, false,
|
|
|
|
"balb", "balb"), UCTY("ucty", "Union City", true, false, "bayf"), WCRK(
|
|
|
|
"wcrk", "Walnut Creek", false, false, "mcar"), WDUB("wdub",
|
|
|
|
"West Dublin/Pleasanton", false, false, "bayf"), WOAK("woak",
|
|
|
|
"West Oakland", false, false), SPCL("spcl", "Special", false, false);
|
2011-05-23 18:59:34 +00:00
|
|
|
|
|
|
|
public final String abbreviation;
|
|
|
|
public final String name;
|
|
|
|
public final boolean invertDirection;
|
|
|
|
protected final String inboundTransferStation;
|
|
|
|
protected final String outboundTransferStation;
|
2012-02-21 17:16:00 +00:00
|
|
|
public final boolean endOfLine;
|
2011-05-23 18:59:34 +00:00
|
|
|
|
2012-04-13 01:07:55 +00:00
|
|
|
private Station(String abbreviation, String name, boolean invertDirection,
|
|
|
|
boolean endOfLine) {
|
2011-05-23 18:59:34 +00:00
|
|
|
this.abbreviation = abbreviation;
|
|
|
|
this.name = name;
|
|
|
|
this.invertDirection = invertDirection;
|
|
|
|
this.inboundTransferStation = null;
|
|
|
|
this.outboundTransferStation = null;
|
2012-02-21 17:16:00 +00:00
|
|
|
this.endOfLine = endOfLine;
|
2011-05-23 18:59:34 +00:00
|
|
|
}
|
|
|
|
|
2012-04-13 01:07:55 +00:00
|
|
|
private Station(String abbreviation, String name, boolean invertDirection,
|
|
|
|
boolean endOfLine, String transferStation) {
|
2011-05-23 18:59:34 +00:00
|
|
|
this.abbreviation = abbreviation;
|
|
|
|
this.name = name;
|
|
|
|
this.invertDirection = invertDirection;
|
|
|
|
this.inboundTransferStation = transferStation;
|
|
|
|
this.outboundTransferStation = null;
|
2012-02-21 17:16:00 +00:00
|
|
|
this.endOfLine = endOfLine;
|
2011-05-23 18:59:34 +00:00
|
|
|
}
|
|
|
|
|
2012-04-13 01:07:55 +00:00
|
|
|
private Station(String abbreviation, String name, boolean invertDirection,
|
|
|
|
boolean endOfLine, String inboundTransferStation,
|
|
|
|
String outboundTransferStation) {
|
2011-05-23 18:59:34 +00:00
|
|
|
this.abbreviation = abbreviation;
|
|
|
|
this.name = name;
|
|
|
|
this.invertDirection = invertDirection;
|
|
|
|
this.inboundTransferStation = inboundTransferStation;
|
|
|
|
this.outboundTransferStation = outboundTransferStation;
|
2012-02-21 17:16:00 +00:00
|
|
|
this.endOfLine = endOfLine;
|
2011-05-23 18:59:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static Station getByAbbreviation(String abbr) {
|
2012-04-13 01:07:55 +00:00
|
|
|
try {
|
|
|
|
if (abbr == null) {
|
|
|
|
return null;
|
|
|
|
} else if (Character.isDigit(abbr.charAt(0))) {
|
|
|
|
return Station.valueOf("_" + abbr.toUpperCase());
|
|
|
|
} else {
|
|
|
|
return Station.valueOf(abbr.toUpperCase());
|
|
|
|
}
|
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
Log.e(Constants.TAG, "Could not find station for '" + abbr + "'", e);
|
2011-05-23 18:59:34 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public Station getInboundTransferStation() {
|
|
|
|
return getByAbbreviation(inboundTransferStation);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Station getOutboundTransferStation() {
|
|
|
|
return getByAbbreviation(outboundTransferStation);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isValidEndpointForDestination(Station dest, Station endpoint) {
|
|
|
|
for (Line line : Line.values()) {
|
|
|
|
int origIndex = line.stations.indexOf(this);
|
|
|
|
if (origIndex < 0)
|
|
|
|
continue;
|
|
|
|
int destIndex = line.stations.indexOf(dest);
|
|
|
|
if (destIndex < 0)
|
|
|
|
continue;
|
|
|
|
int endpointIndex = line.stations.indexOf(endpoint);
|
|
|
|
if (endpointIndex >= 0)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<Route> getRoutesForDestination(Station dest) {
|
2011-05-27 21:06:58 +00:00
|
|
|
return getRoutesForDestination(dest, null);
|
2011-05-23 18:59:34 +00:00
|
|
|
}
|
|
|
|
|
2011-05-27 21:06:58 +00:00
|
|
|
public List<Route> getRoutesForDestination(Station dest,
|
|
|
|
Station transferStation) {
|
2011-05-23 18:59:34 +00:00
|
|
|
if (dest == null)
|
|
|
|
return null;
|
|
|
|
Boolean isNorth = null;
|
|
|
|
List<Route> returnList = new ArrayList<Route>();
|
|
|
|
for (Line line : Line.values()) {
|
|
|
|
int origIndex = line.stations.indexOf(this);
|
|
|
|
if (origIndex < 0)
|
|
|
|
continue;
|
|
|
|
int destIndex = line.stations.indexOf(dest);
|
|
|
|
if (destIndex < 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
isNorth = (origIndex < destIndex);
|
|
|
|
if (line.directionMayInvert && this.invertDirection) {
|
|
|
|
isNorth = !isNorth;
|
|
|
|
}
|
|
|
|
Route route = new Route();
|
|
|
|
route.setOrigin(this);
|
|
|
|
route.setDestination(dest);
|
|
|
|
route.setDirection(isNorth ? "n" : "s");
|
|
|
|
route.setLine(line);
|
2011-05-27 21:06:58 +00:00
|
|
|
if (transferStation != null || line.requiresTransfer) {
|
2011-05-23 18:59:34 +00:00
|
|
|
route.setTransfer(true);
|
|
|
|
} else {
|
|
|
|
route.setTransfer(false);
|
|
|
|
}
|
|
|
|
returnList.add(route);
|
|
|
|
}
|
|
|
|
if (isNorth == null) {
|
|
|
|
if (outboundTransferStation != null) {
|
2012-04-13 01:07:55 +00:00
|
|
|
returnList.addAll(getOutboundTransferStation()
|
|
|
|
.getRoutesForDestination(dest,
|
|
|
|
getOutboundTransferStation()));
|
2011-06-01 03:42:32 +00:00
|
|
|
} else if (dest.getInboundTransferStation() != null) {
|
|
|
|
final List<Route> routesForDestination = getRoutesForDestination(
|
|
|
|
dest.getInboundTransferStation(),
|
|
|
|
dest.getInboundTransferStation());
|
|
|
|
if (routesForDestination != null
|
|
|
|
&& !routesForDestination.isEmpty()) {
|
|
|
|
returnList.addAll(routesForDestination);
|
|
|
|
}
|
2011-05-23 18:59:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return returnList;
|
|
|
|
}
|
|
|
|
|
2011-07-11 19:18:59 +00:00
|
|
|
static public List<Station> getStationList() {
|
|
|
|
List<Station> list = new ArrayList<Station>();
|
|
|
|
for (Station station : values()) {
|
|
|
|
if (!station.equals(Station.SPCL)) {
|
|
|
|
list.add(station);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2011-05-23 18:59:34 +00:00
|
|
|
public String toString() {
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
}
|