/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package messages;
import framework.IHistoryList;
import framework.IPlaneDataObject;
import java.util.LinkedList;
/**
*
* @author m0ng
*/
public class HistoryList implements IHistoryList {
private int size;
private LinkedList<IPlaneDataObject> planeObjects = new LinkedList<IPlaneDataObject>();
public HistoryList(int size) {
this.size = size;
}
public HistoryList() {
this(60);
}
public void setSize(int seconds) {
size = seconds;
}
private boolean isInListLast(IPlaneDataObject pdo) {
double tolerance = 0;
if (getCurrentPosition() != null) {
tolerance = getCurrentPosition().getSpeed() / 3600;
tolerance = tolerance / 60;
}
IPlaneDataObject tmp = planeObjects.peekLast();
if (tmp == null) {
return false;
} else {
return (tmp.getLatitude() - tolerance <= pdo.getLatitude() && tmp.getLatitude() + tolerance >= pdo.getLatitude()) && (tmp.getLongitude() - tolerance <= pdo.getLongitude() && tmp.getLongitude() + tolerance >= pdo.getLongitude());
}
}
public void add(IPlaneDataObject pdo) {
if (!isInListLast(pdo)) {
if (planeObjects.size() >= 200) {
planeObjects.removeFirst();
}
planeObjects.add(pdo);
}
}
public LinkedList getPositionList() {
return planeObjects;
}
public IPlaneDataObject getCurrentPosition() {
IPlaneDataObject tmp = planeObjects.peekLast();
return tmp;
}
}