Class EvictingQueue<E>

  • All Implemented Interfaces:
    Serializable, Iterable<E>, Collection<E>, Queue<E>


    @Beta
     @GwtIncompatible(value="java.util.ArrayDeque")
    public final class EvictingQueue<E>
    extends ForwardingQueue<E>
    implements Serializable
    A non-blocking queue which automatically evicts elements from the head of the queue when attempting to add new elements onto the queue and it is full.

    An evicting queue must be configured with a maximum size. Each time an element is added to a full queue, the queue automatically removes its head element. This is different from conventional bounded queues, which either block or reject new elements when full.

    This class is not thread-safe, and does not accept null elements.

    Since:
    15.0
    See Also:
    Serialized Form
    • Method Detail

      • create

        public static <E> EvictingQueue<E> create(int maxSize)
        Creates and returns a new evicting queue that will hold up to maxSize elements.

        When maxSize is zero, elements will be evicted immediately after being added to the queue.

      • remainingCapacity

        public int remainingCapacity()
        Returns the number of additional elements that this queue can accept without evicting; zero if the queue is currently full.
        Since:
        16.0
      • delegate

        protected Queue<E> delegate()
        Description copied from class: ForwardingObject
        Returns the backing delegate instance that methods are forwarded to. Abstract subclasses generally override this method with an abstract method that has a more specific return type, such as ForwardingSet.delegate(). Concrete subclasses override this method to supply the instance being decorated.
      • offer

        public boolean offer(E e)
        Adds the given element to this queue. If the queue is currently full, the element at the head of the queue is evicted to make room.
        Specified by:
        offer in interface  Queue<E>
        Overrides:
        offer in class  ForwardingQueue<E>
        Returns:
        true always
      • add

        public boolean add(E e)
        Adds the given element to this queue. If the queue is currently full, the element at the head of the queue is evicted to make room.
        Specified by:
        add in interface  Collection<E>
        Specified by:
        add in interface  Queue<E>
        Overrides:
        add in class  ForwardingCollection<E>
        Returns:
        true always
      • addAll

        public boolean addAll(Collection<? extends E> collection)
      • contains

        public boolean contains(Object object)
      • remove

        public boolean remove(Object object)