Class EvictingQueue<T>

Type Parameters:
T - The type of elements in the queue.
All Implemented Interfaces:
Iterable<T>, Collection<T>, Queue<T>

public class EvictingQueue<T> extends Object implements Queue<T>
An EvictingQueue is a non-blocking queue which is limited to a maximum size; when new elements are added to a full queue, elements are evicted from the head of the queue to accommodate the new elements.
  • Constructor Details

    • EvictingQueue

      public EvictingQueue(int maximumSize)
      Construct a new EvictingQueue that holds maximumSize elements.
      maximumSize - The maximum number of elements that the queue can hold
      IllegalArgumentException - if maximumSize is less than zero
  • Method Details

    • remainingCapacity

      public int remainingCapacity()
      the number of additional elements that the queue can accommodate before evictions occur
    • add

      public boolean add(T t)
      Add the given element to the queue, possibly forcing an eviction from the head if remainingCapacity() is zero.
      Specified by:
      add in interface Collection<T>
      Specified by:
      add in interface Queue<T>
      t - the element to add
      true if the element was added (always the case for EvictingQueue
    • offer

      public boolean offer(T t)
      Specified by:
      offer in interface Queue<T>
      See Also:
    • remove

      public T remove()
      Specified by:
      remove in interface Queue<T>
    • poll

      public T poll()
      Specified by:
      poll in interface Queue<T>
    • element

      public T element()
      Specified by:
      element in interface Queue<T>
    • peek

      public T peek()
      Specified by:
      peek in interface Queue<T>
    • size

      public int size()
      Specified by:
      size in interface Collection<T>
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Collection<T>
    • contains

      public boolean contains(Object o)
      Specified by:
      contains in interface Collection<T>
    • iterator

      public Iterator<T> iterator()
      Specified by:
      iterator in interface Collection<T>
      Specified by:
      iterator in interface Iterable<T>
    • toArray

      public Object[] toArray()
      Specified by:
      toArray in interface Collection<T>
    • toArray

      public <T1> T1[] toArray(T1[] a)
      Specified by:
      toArray in interface Collection<T>
    • remove

      public boolean remove(Object o)
      Specified by:
      remove in interface Collection<T>
    • containsAll

      public boolean containsAll(Collection<?> c)
      Specified by:
      containsAll in interface Collection<T>
    • addAll

      public boolean addAll(Collection<? extends T> c)
      Add the given elements to the queue, possibly forcing evictions from the head if remainingCapacity() is zero or becomes zero during the execution of this method.
      Specified by:
      addAll in interface Collection<T>
      c - the collection of elements to add
      true if any elements were added to the queue
    • removeAll

      public boolean removeAll(Collection<?> c)
      Specified by:
      removeAll in interface Collection<T>
    • retainAll

      public boolean retainAll(Collection<?> c)
      Specified by:
      retainAll in interface Collection<T>
    • clear

      public void clear()
      Specified by:
      clear in interface Collection<T>