package com.zhimai.websocket.queue;

import com.zhimai.websocket.util.Logger;

import java.util.LinkedList;

public class MessageQueue {
    private static final String TAG = "---QueueMessageService---";
    private static MessageQueue printMessageQueue;
    private static LinkedList<String> list = new LinkedList();

    private MessageQueue(){}

    public static MessageQueue getInstance(){
        if(printMessageQueue==null){
            printMessageQueue=new MessageQueue();
        }
        return printMessageQueue;
    }

    //进队
    public void enQueue(String o) {
        Logger.e(TAG,"-*-*-*-队列尾部插入消息："+o);
        list.addLast(o);
    }

    //出队
    public Object deQueue() {
        if (!list.isEmpty()) {
            String deletestr=list.removeFirst();
            Logger.e(TAG,"-*-*-*-队列移出消息："+deletestr);
            return deletestr;
        }
        return "队列为空";
    }

    //添加消息到头部（比较优先的消息可以调用此方法）
    public void enQueueHead(String o){
        Logger.e(TAG,"-*-*-*-队列头部插入消息："+o);
        list.add(0,o);
    }

    //判断队列是否为空
    public boolean QueueEmpty() {
        return list.isEmpty();
    }

    //获取队列长度
    public int QueueLength() {
        return list.size();
    }

    //查看队首元素
    public String QueuePeek() {
        return list.getFirst();
    }

    //销毁队列
    public void clear() {
        list.clear();
    }
}
