package com.tzld.piaoquan.recommend.server.framework.candidiate;


import java.util.*;

/**
 * An abstract data type represents a queue of certain item.
 *   一个队列内召回Items完整list
 */
public class Queue<T> implements Iterable<Entry<T>> {
    private final List<Entry<T>> entries;
    private final String name;
    private final String explain;

    public Queue(String name) {
        entries = new ArrayList<Entry<T>>();
        this.name = name;
        this.explain = null;
    }

    public Queue(String name, String explain) {
        this.name = name;
        this.explain = explain;
        this.entries = new ArrayList<Entry<T>>();
    }

    public void reverse() {
        Collections.reverse(this.entries);
    }

    public void add(Entry<T> entry) {
        entries.add(entry);
    }

    public void addAll(Collection<Entry<T>> paramEntries) {
        entries.addAll(paramEntries);
    }

    public List<Entry<T>> get() {
        return entries;
    }

    public Iterator<Entry<T>> iterator() {
        return entries.iterator();
    }

    public int size() {
        return entries.size();
    }

    public void limit(int num) {
        if (!entries.isEmpty() && num >= 0 && num < entries.size()) {
            entries.subList(num, entries.size()).clear();
        }
    }
}