mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-25 15:52:06 +01:00
geoloc: GeoLocation constructor should have Builder as sole paramter
Also remove that (broken) "Error and accuracy set" warning, but mark (get|set)Error() as deprecated.
This commit is contained in:
parent
9b20e2efd8
commit
f5c412a98f
4 changed files with 62 additions and 63 deletions
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2015-2017 Ishan Khanna, Fernando Ramirez, 2019 Florian Schmaus
|
||||
* Copyright 2015-2017 Ishan Khanna, Fernando Ramirez, 2019-2020 Florian Schmaus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -19,14 +19,11 @@ package org.jivesoftware.smackx.geoloc.packet;
|
|||
import java.io.Serializable;
|
||||
import java.net.URI;
|
||||
import java.util.Date;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
|
||||
import org.jivesoftware.smackx.xdata.FormField;
|
||||
|
@ -50,8 +47,6 @@ public final class GeoLocation implements Serializable, ExtensionElement, FormFi
|
|||
|
||||
public static final GeoLocation EMPTY_GEO_LOCATION = GeoLocation.builder().build();
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(GeoLocation.class.getName());
|
||||
|
||||
private final Double accuracy;
|
||||
private final Double alt;
|
||||
private final Double altAccuracy;
|
||||
|
@ -77,50 +72,31 @@ public final class GeoLocation implements Serializable, ExtensionElement, FormFi
|
|||
private final String tzo;
|
||||
private final URI uri;
|
||||
|
||||
private GeoLocation(Double accuracy, Double alt, Double altAccuracy, String area, Double bearing, String building, String country,
|
||||
String countryCode, String datum, String description, Double error, String floor, Double lat,
|
||||
String locality, Double lon, String postalcode, String region, String room, Double speed,
|
||||
String street, String text, Date timestamp, String tzo, URI uri) {
|
||||
this.accuracy = accuracy;
|
||||
this.alt = alt;
|
||||
this.altAccuracy = altAccuracy;
|
||||
this.area = area;
|
||||
this.bearing = bearing;
|
||||
this.building = building;
|
||||
this.country = country;
|
||||
this.countryCode = countryCode;
|
||||
|
||||
// If datum is not included, receiver MUST assume WGS84; receivers MUST implement WGS84; senders MAY use another
|
||||
// datum, but it is not recommended.
|
||||
|
||||
if (StringUtils.isNullOrEmpty(datum)) {
|
||||
datum = "WGS84";
|
||||
}
|
||||
|
||||
this.datum = datum;
|
||||
this.description = description;
|
||||
|
||||
// error element is deprecated in favor of accuracy
|
||||
if (accuracy != null) {
|
||||
error = null;
|
||||
LOGGER.log(Level.WARNING,
|
||||
"Error and accuracy set. Ignoring error as it is deprecated in favor of accuracy");
|
||||
}
|
||||
|
||||
this.error = error;
|
||||
this.floor = floor;
|
||||
this.lat = lat;
|
||||
this.locality = locality;
|
||||
this.lon = lon;
|
||||
this.postalcode = postalcode;
|
||||
this.region = region;
|
||||
this.room = room;
|
||||
this.speed = speed;
|
||||
this.street = street;
|
||||
this.text = text;
|
||||
this.timestamp = timestamp;
|
||||
this.tzo = tzo;
|
||||
this.uri = uri;
|
||||
private GeoLocation(Builder builder) {
|
||||
accuracy = builder.accuracy;
|
||||
alt = builder.alt;
|
||||
altAccuracy = builder.altAccuracy;
|
||||
area = builder.area;
|
||||
bearing = builder.bearing;
|
||||
building = builder.building;
|
||||
country = builder.country;
|
||||
countryCode = builder.countryCode;
|
||||
datum = builder.datum;
|
||||
description = builder.description;
|
||||
error = builder.error;
|
||||
floor = builder.floor;
|
||||
lat = builder.lat;
|
||||
locality = builder.locality;
|
||||
lon = builder.lon;
|
||||
postalcode = builder.postalcode;
|
||||
region = builder.region;
|
||||
room = builder.room;
|
||||
speed = builder.speed;
|
||||
street = builder.street;
|
||||
text = builder.text;
|
||||
timestamp = builder.timestamp;
|
||||
tzo = builder.tzo;
|
||||
uri = builder.uri;
|
||||
}
|
||||
|
||||
public Double getAccuracy() {
|
||||
|
@ -163,6 +139,13 @@ public final class GeoLocation implements Serializable, ExtensionElement, FormFi
|
|||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the error.
|
||||
*
|
||||
* @return the error.
|
||||
* @deprecated use {@link #getAccuracy()} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public Double getError() {
|
||||
return error;
|
||||
}
|
||||
|
@ -318,7 +301,11 @@ public final class GeoLocation implements Serializable, ExtensionElement, FormFi
|
|||
private String building;
|
||||
private String country;
|
||||
private String countryCode;
|
||||
private String datum;
|
||||
|
||||
// If datum is not included, receiver MUST assume WGS84; receivers MUST implement WGS84; senders MAY use another
|
||||
// datum, but it is not recommended.
|
||||
private String datum = "WGS84";
|
||||
|
||||
private String description;
|
||||
private Double error;
|
||||
private String floor;
|
||||
|
@ -453,7 +440,9 @@ public final class GeoLocation implements Serializable, ExtensionElement, FormFi
|
|||
*
|
||||
* @param error error in arc minutes
|
||||
* @return Builder
|
||||
* @deprecated use {@link #setAccuracy(Double)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public Builder setError(Double error) {
|
||||
this.error = error;
|
||||
return this;
|
||||
|
@ -610,10 +599,7 @@ public final class GeoLocation implements Serializable, ExtensionElement, FormFi
|
|||
* @return GeoLocation
|
||||
*/
|
||||
public GeoLocation build() {
|
||||
|
||||
return new GeoLocation(accuracy, alt, altAccuracy, area, bearing, building, country, countryCode, datum, description,
|
||||
error, floor, lat, locality, lon, postalcode, region, room, speed, street, text, timestamp,
|
||||
tzo, uri);
|
||||
return new GeoLocation(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2015-2017 Ishan Khanna, Fernando Ramirez, 2019 Florian Schmaus
|
||||
* Copyright 2015-2017 Ishan Khanna, Fernando Ramirez, 2019-2020 Florian Schmaus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -79,7 +79,7 @@ public class GeoLocationProvider extends ExtensionElementProvider<GeoLocation> {
|
|||
builder.setDescription(parser.nextText());
|
||||
break;
|
||||
case "error":
|
||||
builder.setError(ParserUtils.getDoubleFromNextText(parser));
|
||||
parseError(builder, parser);
|
||||
break;
|
||||
case "floor":
|
||||
builder.setFloor(parser.nextText());
|
||||
|
@ -136,6 +136,12 @@ public class GeoLocationProvider extends ExtensionElementProvider<GeoLocation> {
|
|||
return builder.build();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private static void parseError(GeoLocation.Builder builder, XmlPullParser parser) throws XmlPullParserException, IOException {
|
||||
double error = ParserUtils.getDoubleFromNextText(parser);
|
||||
builder.setError(error);
|
||||
}
|
||||
|
||||
public static class GeoLocationFormFieldChildElementProvider extends FormFieldChildElementProvider<GeoLocation> {
|
||||
|
||||
public static final GeoLocationFormFieldChildElementProvider INSTANCE = new GeoLocationFormFieldChildElementProvider();
|
||||
|
|
|
@ -121,6 +121,7 @@ public class GeoLocationTest extends SmackTestSuite {
|
|||
assertNotNull(geoLocation);
|
||||
assertNotNull(geoLocation.toXML());
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
GeoLocation constructedGeoLocation = GeoLocation.builder().setAccuracy(23d).setAlt(1000d).setAltAccuracy(10d).setArea("Delhi").setBearing(
|
||||
10d).setBuilding("Small Building").setCountry("India").setCountryCode("IN").setDescription(
|
||||
"My Description").setError(90d).setFloor("top").setLat(25.098345d).setLocality("awesome").setLon(
|
||||
|
|
|
@ -18,7 +18,6 @@ package org.jivesoftware.smackx.geoloc.provider;
|
|||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
|
@ -82,7 +81,9 @@ public class GeoLocationProviderTest extends SmackTestSuite {
|
|||
assertEquals("IN", geoLocation.getCountryCode());
|
||||
assertEquals("WGS84", geoLocation.getDatum());
|
||||
assertEquals("My Description", geoLocation.getDescription());
|
||||
assertNull(geoLocation.getError());
|
||||
@SuppressWarnings("deprecation")
|
||||
Double error = geoLocation.getError();
|
||||
assertEquals(90, error);
|
||||
assertEquals("top", geoLocation.getFloor());
|
||||
assertEquals((Double) 25.098345d, geoLocation.getLat());
|
||||
assertEquals("awesome", geoLocation.getLocality());
|
||||
|
@ -150,7 +151,9 @@ public class GeoLocationProviderTest extends SmackTestSuite {
|
|||
assertEquals("IN", geoLocation.getCountryCode());
|
||||
assertEquals("Test Datum", geoLocation.getDatum());
|
||||
assertEquals("My Description", geoLocation.getDescription());
|
||||
assertNull(geoLocation.getError());
|
||||
@SuppressWarnings("deprecation")
|
||||
Double error = geoLocation.getError();
|
||||
assertEquals(90, error);
|
||||
assertEquals("top", geoLocation.getFloor());
|
||||
assertEquals((Double) 25.098345d, geoLocation.getLat());
|
||||
assertEquals("awesome", geoLocation.getLocality());
|
||||
|
@ -183,7 +186,9 @@ public class GeoLocationProviderTest extends SmackTestSuite {
|
|||
|
||||
GeoLocation geoLocation = messageWithGeoLocation.getExtension(GeoLocation.class);
|
||||
|
||||
assertEquals((Double) 90d, geoLocation.getError());
|
||||
@SuppressWarnings("deprecation")
|
||||
Double error = geoLocation.getError();
|
||||
assertEquals((Double) 90d, error);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -223,8 +228,9 @@ public class GeoLocationProviderTest extends SmackTestSuite {
|
|||
GeoLocation geoLocation = messageWithGeoLocation.getExtension(GeoLocation.class);
|
||||
|
||||
assertEquals((Double) 90d, geoLocation.getAccuracy());
|
||||
assertNull(geoLocation.getError());
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
Double error = geoLocation.getError();
|
||||
assertEquals(100, error);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue