kopia lustrzana https://github.com/bertrik/ttnhabbridge
Use Double.NaN instead of null to indicate missing location.
rodzic
2ae6f9b83d
commit
4e676e69e7
|
@ -5,9 +5,9 @@ package nl.sikken.bertrik.hab.habitat;
|
|||
*/
|
||||
public final class Location {
|
||||
|
||||
private final Double lat;
|
||||
private final Double lon;
|
||||
private final Double alt;
|
||||
private final double lat;
|
||||
private final double lon;
|
||||
private final double alt;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
|
@ -16,29 +16,29 @@ public final class Location {
|
|||
* @param lon longitude (degrees)
|
||||
* @param alt altitude (meter)
|
||||
*/
|
||||
public Location(Double lat, Double lon, Double alt) {
|
||||
public Location(double lat, double lon, double alt) {
|
||||
this.lat = lat;
|
||||
this.lon = lon;
|
||||
this.alt = alt;
|
||||
}
|
||||
|
||||
public Double getLat() {
|
||||
public double getLat() {
|
||||
return lat;
|
||||
}
|
||||
|
||||
public Double getLon() {
|
||||
public double getLon() {
|
||||
return lon;
|
||||
}
|
||||
|
||||
public Double getAlt() {
|
||||
public double getAlt() {
|
||||
return alt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if this is a fully valid location
|
||||
* @return true if this is a valid location (has latitude and longitude)
|
||||
*/
|
||||
public boolean isValid() {
|
||||
return (lat != null) && (lon != null) && (alt != null);
|
||||
return Double.isFinite(lat) && Double.isFinite(lon);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -36,8 +36,11 @@ public final class ListenerInformationDoc extends ListenerDoc {
|
|||
ObjectNode node = factory().objectNode();
|
||||
node.set("callsign", factory().textNode(receiver.getCallsign()));
|
||||
node.set("radio", factory().textNode("TheThingsNetwork"));
|
||||
String antenna = String.format(Locale.US, "%.0f m", receiver.getLocation().getAlt());
|
||||
node.set("antenna", factory().textNode(antenna));
|
||||
double altitude = receiver.getLocation().getAlt();
|
||||
if (Double.isFinite(altitude)) {
|
||||
String antenna = String.format(Locale.ROOT, "%.0f m", altitude);
|
||||
node.set("antenna", factory().textNode(antenna));
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,13 +22,13 @@ public final class TtnMessageGateway {
|
|||
private String time;
|
||||
|
||||
@JsonProperty("latitude")
|
||||
private Double latitude = Double.NaN;
|
||||
private double latitude = Double.NaN;
|
||||
|
||||
@JsonProperty("longitude")
|
||||
private Double longitude = Double.NaN;
|
||||
private double longitude = Double.NaN;
|
||||
|
||||
@JsonProperty("altitude")
|
||||
private Double altitude = Double.NaN;
|
||||
private double altitude = Double.NaN;
|
||||
|
||||
private TtnMessageGateway() {
|
||||
// jackson constructor
|
||||
|
@ -44,7 +44,7 @@ public final class TtnMessageGateway {
|
|||
* @param lon the longitude (degrees)
|
||||
* @param alt the altitude (meters)
|
||||
*/
|
||||
public TtnMessageGateway(String id, boolean trusted, String time, Double lat, Double lon, Double alt) {
|
||||
public TtnMessageGateway(String id, boolean trusted, String time, double lat, double lon, double alt) {
|
||||
this();
|
||||
this.id = id;
|
||||
this.trusted = trusted;
|
||||
|
|
|
@ -46,10 +46,10 @@ public final class TtnMessageGatewayTest {
|
|||
*/
|
||||
@Test
|
||||
public void testNoLocation() {
|
||||
TtnMessageGateway gw1 = new TtnMessageGateway("id", true, "time", null, null, null);
|
||||
TtnMessageGateway gw1 = new TtnMessageGateway("id", true, "time", Double.NaN, Double.NaN, Double.NaN);
|
||||
Assert.assertFalse(gw1.getLocation().isValid());
|
||||
|
||||
TtnMessageGateway gw2 = new TtnMessageGateway("id", true, "time", null, 1.1, 2.2);
|
||||
TtnMessageGateway gw2 = new TtnMessageGateway("id", true, "time", Double.NaN, 1.1, 2.2);
|
||||
Assert.assertFalse(gw2.getLocation().isValid());
|
||||
}
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue