package com.qianwen.core.tool.metadata.types;
|
|
import com.alibaba.fastjson.JSON;
|
import java.io.Serializable;
|
import java.math.BigDecimal;
|
import java.util.Collection;
|
import java.util.Map;
|
import com.qianwen.core.tool.utils.StringPool;
|
import org.springframework.lang.Nullable;
|
|
/* loaded from: blade-core-tool-9.3.0.0-SNAPSHOT.jar:org/springblade/core/tool/metadata/types/GeoPoint.class */
|
public class GeoPoint implements Serializable {
|
private static final long serialVersionUID = -6849794470754667710L;
|
private double lon;
|
private double lat;
|
|
public void setLon(final double lon) {
|
this.lon = lon;
|
}
|
|
public void setLat(final double lat) {
|
this.lat = lat;
|
}
|
|
public GeoPoint(final double lon, final double lat) {
|
this.lon = lon;
|
this.lat = lat;
|
}
|
|
public GeoPoint() {
|
}
|
|
public double getLon() {
|
return this.lon;
|
}
|
|
public double getLat() {
|
return this.lat;
|
}
|
|
public static GeoPoint of(Object val) {
|
if (val == null) {
|
return null;
|
}
|
if (val instanceof GeoPoint) {
|
return (GeoPoint) val;
|
}
|
if (val instanceof String) {
|
String strVal = String.valueOf(val);
|
if (strVal.startsWith(StringPool.LEFT_BRACE)) {
|
val = JSON.parseObject(strVal);
|
} else if (strVal.startsWith(StringPool.LEFT_SQ_BRACKET)) {
|
val = JSON.parseArray(strVal);
|
} else {
|
val = strVal.split("[,]");
|
}
|
}
|
if (val instanceof Map) {
|
Map<Object, Object> mapVal = (Map) val;
|
Object lon = mapVal.getOrDefault("lon", mapVal.get("x"));
|
Object lat = mapVal.getOrDefault("lat", mapVal.get(StringPool.Y));
|
val = new Object[]{lon, lat};
|
}
|
if (val instanceof Collection) {
|
val = ((Collection) val).toArray();
|
}
|
if (val instanceof Object[]) {
|
Object[] arr = (Object[]) val;
|
if (arr.length >= 2) {
|
return new GeoPoint(new BigDecimal(String.valueOf(arr[0])).doubleValue(), new BigDecimal(String.valueOf(arr[1])).doubleValue());
|
}
|
}
|
throw new IllegalArgumentException("unsupported geo format:" + val);
|
}
|
|
public int hashCode() {
|
long temp = Double.doubleToLongBits(this.lat);
|
int result = (31 * 1) + ((int) (temp ^ (temp >>> 32)));
|
long temp2 = Double.doubleToLongBits(this.lon);
|
return (31 * result) + ((int) (temp2 ^ (temp2 >>> 32)));
|
}
|
|
public boolean equals(@Nullable Object obj) {
|
if (this == obj) {
|
return true;
|
}
|
if (!(obj instanceof GeoPoint)) {
|
return false;
|
}
|
GeoPoint other = (GeoPoint) obj;
|
return Double.doubleToLongBits(this.lon) == Double.doubleToLongBits(other.lon) && Double.doubleToLongBits(this.lat) == Double.doubleToLongBits(other.lat);
|
}
|
|
public String toString() {
|
return this.lon + StringPool.COMMA + this.lat;
|
}
|
}
|