2010-05-14 23:05:18 +02:00
|
|
|
package com.osmand.data;
|
|
|
|
|
|
|
|
import com.osmand.osm.Entity;
|
|
|
|
import com.osmand.osm.LatLon;
|
|
|
|
import com.osmand.osm.MapUtils;
|
|
|
|
import com.osmand.osm.OSMSettings.OSMTagKey;
|
|
|
|
|
|
|
|
public abstract class MapObject<T extends Entity> implements Comparable<MapObject<T>> {
|
|
|
|
|
|
|
|
protected String name = null;
|
|
|
|
protected LatLon location = null;
|
2010-05-16 23:49:11 +02:00
|
|
|
protected Long id = null;
|
|
|
|
// could be null
|
2010-05-17 14:03:16 +02:00
|
|
|
protected T entity = null;
|
|
|
|
|
|
|
|
public MapObject(){}
|
|
|
|
|
|
|
|
public MapObject(T e){
|
|
|
|
entity = e;
|
|
|
|
}
|
|
|
|
|
|
|
|
public T getEntity(){
|
|
|
|
return entity;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setEntity(T e){
|
|
|
|
entity = e;
|
|
|
|
}
|
2010-05-14 23:05:18 +02:00
|
|
|
|
2010-05-16 23:49:11 +02:00
|
|
|
public void setId(Long id) {
|
|
|
|
this.id = id;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Long getId() {
|
|
|
|
if(id != null){
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
T e = getEntity();
|
|
|
|
if(e != null){
|
|
|
|
return e.getId();
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2010-05-14 23:05:18 +02:00
|
|
|
public String getName() {
|
|
|
|
if (this.name != null) {
|
|
|
|
return this.name;
|
|
|
|
}
|
|
|
|
Entity e = getEntity();
|
|
|
|
if (e != null) {
|
|
|
|
String name = getEntity().getTag(OSMTagKey.NAME);
|
|
|
|
if (name != null) {
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
return e.getId() + "";
|
|
|
|
} else {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setName(String name) {
|
|
|
|
this.name = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
public LatLon getLocation(){
|
|
|
|
if(location != null){
|
|
|
|
return location;
|
|
|
|
}
|
|
|
|
return MapUtils.getCenter(getEntity());
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setLocation(double latitude, double longitude){
|
|
|
|
location = new LatLon(latitude, longitude);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int compareTo(MapObject<T> o) {
|
|
|
|
return getName().compareTo(o.getName());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|