package com.tsi.navi.vo;

import java.util.HashMap;
import java.util.Map;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class TsiGpsTrackingVo {
    private long[] reservedNodeId = new long[] { 0, 0, 0, 0, 0 };

    private int signalDirCode;
    private NodeVo inCrossNode;
    private NodeVo startNode;
    private NodeVo endNode;
    private NodeVo toNode;
    private NodeVo requestNode;

    public TsiGpsTrackingVo() {
        init();
    }

    public void init() {
        this.signalDirCode = 0;
        this.inCrossNode = null;;
        this.startNode = null;
        this.endNode = null;
        this.toNode = null;
        this.requestNode = null;

        clearReservedNodeId();
    }

    public void clearReservedNodeId() {
        for (int ii = 0; ii < this.reservedNodeId.length; ii++) {
            this.reservedNodeId[ii] = 0;
        }
    }
    public void addReservedNodeId(long nodeId) {
        for (int ii = this.reservedNodeId.length-1; ii > 1; ii--) {
            this.reservedNodeId[ii] = this.reservedNodeId[ii-1];
        }
        this.reservedNodeId[0] = nodeId;
    }

    public long getReservedNodeId() {
        HashMap<Long, Integer> nodeMap = new HashMap();
        for (int ii = 0; ii < this.reservedNodeId.length; ii++) {
            if (this.reservedNodeId[ii] != 0) {
                Integer nodeCnt = nodeMap.get(this.reservedNodeId[ii]);
                if (nodeCnt == null) {
                    nodeMap.put(this.reservedNodeId[ii], 1);
                }
                else {
                    nodeCnt++;
                    nodeMap.put(this.reservedNodeId[ii], nodeCnt);
                }
            }
        }
        long nodeId = 0;
        int maxCnt = 0;
        for (Map.Entry<Long, Integer> obj : nodeMap.entrySet()) {
            if (obj.getValue() > maxCnt) {
                nodeId = obj.getKey();
                maxCnt = obj.getValue();
            }
        }
        return nodeId;
    }

}
