정말로 변경할 수있는 GeoPoint
이 필요합니까? GeoPoint의 연속적인 인스턴스를 만드는 것이 성능상의 문제가 될 것이라고 확신합니까? 네이트가 말했듯이 위도와 경도를 원시 변수로 유지하고 필요할 때만 GeoPoint로 변환 할 수 있습니까? 아니면 각각 하나가 GeoPoint가 될 필요가 있습니까?
변경 가능한 GeoPoint가 필요하다고 확신하는 경우 변경할 수 있습니다. GeoPoint 클래스는 final
이 아니므로 확장 할 수 있습니다. 그러나 변경 가능한 객체를 HashMap
, HashSet
또는 다른 해시 기반 컬렉션에 넣는 것은 놀라 울 정도로 (그리고 버그가있는) 결과를 가져올 것입니다.
실수로 명시 적으로 처리하지 않아도 실수로 컬렉션에 넣지 않는 API로 전달하지 않도록주의하십시오.
import com.google.android.maps.GeoPoint;
public class MutableGeoPoint extends GeoPoint {
private int latitudeE6, longitudeE6;
public MutableGeoPoint(int latitudeE6, int longitudeE6) {
super(0, 0); // the values in the superclass are moot
this.latitudeE6 = latitudeE6;
this.longitudeE6 = longitudeE6;
}
@Override
public int getLatitudeE6() {
return latitudeE6;
}
@Override
public int getLongitudeE6() {
return longitudeE6;
}
public void setLatitudeE6(int value) {
this.latitudeE6 = value;
}
public void setLongitudeE6(int value) {
this.longitudeE6 = value;
}
@Override
public int hashCode() {
return 29*latitudeE6 + longitudeE6;
}
@Override
public String toString() {
return latitudeE6 + "," + longitudeE6;
}
}
hashCode() 메소드를 Google의 GeoPoint 클래스와 동일하게 변경하여 편집합니다.
(GeoPoint의와 MutableGeoPoint 그
빠르게 같은 것들에 대한 걱정. equals와 동일 비교 수확 체감의 지점에 도달하지 않습니다.)
을 답변 중 하나가 당신의 문제가 해결되면, 당신은 그것을 받아 들여야한다. –