package mediawiki.info.wikibase.snaks;
import javat.xml.Element;
import org.json.JSONException;
import org.json.JSONObject;
import mediawiki.info.wikibase.ValueSnak;
import mediawiki.info.wikibase.WikibaseCoordinate;
public class CoordinateSnak extends ValueSnak<WikibaseCoordinate> {
public CoordinateSnak(WikibaseCoordinate value) {
super(value);
}
public CoordinateSnak(Double lat, Double lon,int precision){
this(new WikibaseCoordinate(lat, lon, precision));
}
@Override
public JSONObject toJSONObject() throws JSONException {
JSONObject o = new JSONObject();
o.put("latitude", getValue().getLatitude());
o.put("longitude", getValue().getLongitude());
o.put("altitude", getValue().getAltitude());
o.put("precision", getValue().getPrecision());
o.put("globe", getValue().getGlobe());
return o;
}
@Override
public JSONObject toReferenceRepresentation() throws JSONException {
JSONObject o = new JSONObject();
o.put("type", "globecoordinate");
o.put("value", toJSONObject());
return o;
}
@Override
public JSONObject toClaimRepresentation() throws JSONException {
return toJSONObject();
}
@Override
public void convert(Element element) throws Exception {
Element e = element.getChildren("value").get(0);
Double latitude = e.getAttribute("latitude") == null ? null : Double.parseDouble(e.getAttribute("latitude").getValue());
Double longitude = e.getAttribute("longitude") == null ? null :Double.parseDouble(e.getAttribute("longitude").getValue());
Double altitude = e.getAttribute("altitude") == null || e.getAttribute("altitude").getValue().equals("") ? null : Double.parseDouble(e.getAttribute("altitude").getValue());
Double precision = e.getAttribute("precision") == null ? null : Double.parseDouble(e.getAttribute("precision").getValue());
String globe = e.getAttribute("globe") == null ? null : e.getAttribute("globe").getValue();
setValue(new WikibaseCoordinate(latitude, longitude, altitude, precision, globe));
}
@Override
public String getDatatype() {
return "globe-coordinate";
}
}