2010-04-27 14:37:49 +02:00
|
|
|
package com.osmand.osm;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2010-04-27 22:37:40 +02:00
|
|
|
import java.util.Collections;
|
2010-04-27 14:37:49 +02:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
public class Way extends Entity {
|
|
|
|
|
|
|
|
// lazy loading
|
|
|
|
private List<Long> nodeIds = null;
|
|
|
|
private List<Node> nodes = null;
|
|
|
|
|
|
|
|
public Way(long id) {
|
|
|
|
super(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void addNode(long id){
|
|
|
|
if(nodeIds == null){
|
|
|
|
nodeIds = new ArrayList<Long>();
|
|
|
|
}
|
|
|
|
nodeIds.add(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Long removeNodeByIndex(int i){
|
|
|
|
if(nodeIds == null){
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return nodeIds.remove(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<Long> getNodeIds(){
|
2010-04-27 22:37:40 +02:00
|
|
|
if(nodeIds == null){
|
|
|
|
return Collections.emptyList();
|
|
|
|
}
|
2010-04-27 14:37:49 +02:00
|
|
|
return nodeIds;
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<Node> getNodes() {
|
2010-04-27 22:37:40 +02:00
|
|
|
if(nodes == null){
|
|
|
|
return Collections.emptyList();
|
|
|
|
}
|
2010-04-27 14:37:49 +02:00
|
|
|
return nodes;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void initializeLinks(Map<Long, Entity> entities) {
|
|
|
|
if (nodeIds != null) {
|
|
|
|
if(nodes == null){
|
|
|
|
nodes = new ArrayList<Node>();
|
|
|
|
} else {
|
|
|
|
nodes.clear();
|
|
|
|
}
|
|
|
|
for (int i = 0; i < nodeIds.size(); i++) {
|
|
|
|
if(entities.get(nodeIds.get(i)) instanceof Node){
|
|
|
|
nodes.add((Node) entities.get(nodeIds.get(i)));
|
|
|
|
} else {
|
|
|
|
nodes.add(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public LatLon getLatLon() {
|
|
|
|
if(nodes == null){
|
|
|
|
return null;
|
|
|
|
}
|
2010-05-14 23:05:18 +02:00
|
|
|
return MapUtils.getWeightCenterForNodes(nodes);
|
2010-04-27 14:37:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|