org.opentripplanner.openstreetmap.model.OSMMap Maven / Gradle / Ivy
package org.opentripplanner.openstreetmap.model;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.opentripplanner.openstreetmap.services.OpenStreetMapContentHandler;
/**
* A simplistic implementation of OSMContentHandler that simply stores all of the ways, nodes, and
* relations in maps keyed by ids. For memory usage reasons, this is only used in tests.
*
*/
public class OSMMap implements OpenStreetMapContentHandler {
private Map nodes = new HashMap();
private Map ways = new HashMap();
private Map relations = new HashMap();
public Map getNodes() {
return nodes;
}
public OSMNode getNodeForId(long nodeId) {
return nodes.get(nodeId);
}
public Map getWays() {
return ways;
}
public OSMWay getWayForId(long wayId) {
return ways.get(wayId);
}
public void pruneUnusedNodes() {
Set nodes = new HashSet();
for (OSMWay way : ways.values()) {
for (long id : way.getNodeRefs())
nodes.add(id);
}
this.nodes.keySet().retainAll(nodes);
}
/****
* {@link OpenStreetMapContentHandler} Interface
****/
public void addNode(OSMNode node) {
nodes.put(node.getId(), node);
}
public void addWay(OSMWay way) {
ways.put(way.getId(), way);
}
public void addRelation(OSMRelation relation) {
relations.put(relation.getId(), relation);
}
@Override
public void doneFirstPhaseRelations() {
}
@Override
public void doneSecondPhaseWays() {
}
@Override
public void doneThirdPhaseNodes() {
}
}