} // END buildGraph()
private void processBikeRentalNodes() {
LOG.info("Processing bike rental nodes...");
int n = 0;
BikeRentalStationService bikeRentalService = graph.getService(
BikeRentalStationService.class, true);
graph.putService(BikeRentalStationService.class, bikeRentalService);
for (OSMNode node : osmdb.getBikeRentalNodes()) {
n++;
String creativeName = wayPropertySet.getCreativeNameForWay(node);
int capacity = Integer.MAX_VALUE;
if (node.hasTag("capacity")) {
try {
capacity = node.getCapacity();
} catch (NumberFormatException e) {
LOG.warn("Capacity for osm node " + node.getId() + " (" + creativeName
+ ") is not a number: " + node.getTag("capacity"));
}
}
String networks = node.getTag("network");
String operators = node.getTag("operator");
Set<String> networkSet = new HashSet<String>();
if (networks != null)
networkSet.addAll(Arrays.asList(networks.split(";")));
if (operators != null)
networkSet.addAll(Arrays.asList(operators.split(";")));
if (networkSet.isEmpty()) {
LOG.warn("Bike rental station at osm node " + node.getId() + " ("
+ creativeName + ") with no network; including as compatible-with-all.");
networkSet = null; // Special "catch-all" value
}
BikeRentalStation station = new BikeRentalStation();
station.id = "" + node.getId();
station.name = creativeName;
station.x = node.lon;
station.y = node.lat;
// The following make sure that spaces+bikes=capacity, always.
// Also, for the degenerate case of capacity=1, we should have 1
// bike available, not 0.
station.spacesAvailable = capacity / 2;
station.bikesAvailable = capacity - station.spacesAvailable;
station.realTimeData = false;
bikeRentalService.addBikeRentalStation(station);
BikeRentalStationVertex stationVertex = new BikeRentalStationVertex(graph, station);
new RentABikeOnEdge(stationVertex, stationVertex, networkSet);
new RentABikeOffEdge(stationVertex, stationVertex, networkSet);
}
LOG.info("Created " + n + " bike rental stations.");