All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.alibaba.rocketmq.common.queue.RoundQueue Maven / Gradle / Ivy

package com.alibaba.rocketmq.common.queue;

import java.util.LinkedList;
import java.util.Queue;


/**
 * not thread safe
 * 
 * @auther lansheng.zj
 */
public class RoundQueue {

    private Queue queue;
    private int capacity;


    public RoundQueue(int capacity) {
        this.capacity = capacity;
        queue = new LinkedList();
    }


    public boolean put(E e) {
        boolean ok = false;
        if (!queue.contains(e)) {
            if (queue.size() >= capacity) {
                queue.poll();
            }
            queue.add(e);
            ok = true;
        }

        return ok;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy