From be4974518d4e24f66c19ceffc1e633e3e306956b Mon Sep 17 00:00:00 2001 From: Ben Burwell Date: Sun, 20 Nov 2016 01:14:47 -0500 Subject: Show track and remove planes after interval --- .../java/com/benburwell/planes/data/Aircraft.java | 26 +++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'src/main/java/com/benburwell/planes/data/Aircraft.java') diff --git a/src/main/java/com/benburwell/planes/data/Aircraft.java b/src/main/java/com/benburwell/planes/data/Aircraft.java index 66a7a46..9f6b881 100644 --- a/src/main/java/com/benburwell/planes/data/Aircraft.java +++ b/src/main/java/com/benburwell/planes/data/Aircraft.java @@ -2,6 +2,7 @@ package com.benburwell.planes.data; import com.benburwell.planes.sbs.SBSPacket; +import java.util.Date; import java.util.List; import java.util.ArrayList; @@ -25,14 +26,24 @@ public class Aircraft implements Comparable { public void handleUpdate(SBSPacket packet) { this.packetCount++; + + Position newPosition = new Position(); + newPosition.setAltitude(this.currentPosition.getAltitude()); + newPosition.setLatitude(this.currentPosition.getLatitude()); + newPosition.setLongitude(this.currentPosition.getLongitude()); + newPosition.setTimestamp(this.currentPosition.getTimestamp()); + if (packet.getAltitude() != null) { - this.currentPosition.setAltitude(packet.getAltitude()); + newPosition.setAltitude(packet.getAltitude()); + newPosition.setTimestamp(new Date(System.currentTimeMillis())); } if (packet.getLatitude() != null) { - this.currentPosition.setLatitude(packet.getLatitude()); + newPosition.setLatitude(packet.getLatitude()); + newPosition.setTimestamp(new Date(System.currentTimeMillis())); } if (packet.getLongitude() != null) { - this.currentPosition.setLongitude(packet.getLongitude()); + newPosition.setLongitude(packet.getLongitude()); + newPosition.setTimestamp(new Date(System.currentTimeMillis())); } if (packet.getCallsign() != null && !packet.getCallsign().isEmpty()) { this.callsign = packet.getCallsign(); @@ -49,6 +60,11 @@ public class Aircraft implements Comparable { if (packet.getVerticalRate() != null) { this.verticalRate = packet.getVerticalRate(); } + + if (newPosition.getTimestamp().after(this.currentPosition.getTimestamp())) { + this.positionHistory.add(currentPosition); + this.currentPosition = newPosition; + } } public Position getCurrentPosition() { @@ -83,6 +99,10 @@ public class Aircraft implements Comparable { return this.verticalRate; } + public List getPositionHistory() { + return positionHistory; + } + @Override public int compareTo(Aircraft that) { return this.getHexIdent().compareTo(that.getHexIdent()); -- cgit v1.2.3