Package messages

Source Code of messages.HistoryList

/*
* 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;
    }
}
TOP

Related Classes of messages.HistoryList

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.