package net.osmand.osm; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; public class Way extends Entity { // lazy loading private List nodeIds = null; private List nodes = null; public Way(long id) { super(id); } public void addNode(long id){ if(nodeIds == null){ nodeIds = new ArrayList(); } nodeIds.add(id); } public void addNode(Node n){ if(nodeIds == null){ nodeIds = new ArrayList(); } if(nodes == null){ nodes = new ArrayList(); } nodeIds.add(n.getId()); nodes.add(n); } public Long removeNodeByIndex(int i){ if(nodeIds == null){ return null; } return nodeIds.remove(i); } public List getNodeIds(){ if(nodeIds == null){ return Collections.emptyList(); } return nodeIds; } public List getEntityIds(){ if(nodeIds == null){ return Collections.emptyList(); } List ls = new ArrayList(); for(Long l : nodeIds){ ls.add(new EntityId(EntityType.NODE, l)); } return ls; } public List getNodes() { if(nodes == null){ return Collections.emptyList(); } return nodes; } @Override public void initializeLinks(Map entities) { if (nodeIds != null) { if(nodes == null){ nodes = new ArrayList(); } else { nodes.clear(); } for (int i = 0; i < nodeIds.size(); i++) { nodes.add((Node) entities.get(new EntityId(EntityType.NODE,nodeIds.get(i)))); } } } @Override public LatLon getLatLon() { if(nodes == null){ return null; } return MapUtils.getWeightCenterForNodes(nodes); } }