Package 

Class EvictingQueue

  • All Implemented Interfaces:
    java.util.Queue , kotlin.collections.Collection , kotlin.collections.Iterable , kotlin.collections.MutableCollection , kotlin.collections.MutableIterable

    
    public final class EvictingQueue<T extends Object>
     implements Queue<T>
                        

    A bounded queue that automatically evicts the oldest elements when new elements are added beyond its maximum capacity.

    This implementation delegates all Queue operations to an underlying LinkedList. It provides a FIFO (first-in, first-out) behavior with a fixed maximum size. When new elements are added and the queue is at capacity, the oldest element is evicted.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private final Integer size
    • Constructor Summary

      Constructors 
      Constructor Description
      EvictingQueue(Integer maxSize) Secondary constructor that initializes the EvictingQueue with the given maxSize.
    • Method Summary

      Modifier and Type Method Description
      Integer getSize()
      Boolean add(T element) Adds the specified element to the end of this queue.
      Boolean offer(T element) Adds the specified element to the end of this queue.
      Boolean addAll(Collection<T> elements) Adds all of the elements in the specified elements collection to the end of this queue.
      • Methods inherited from class java.util.Queue

        clear, iterator, remove, removeAll, removeIf, retainAll
      • Methods inherited from class com.datadog.android.internal.collections.EvictingQueue

        element, peek, poll, remove
      • Methods inherited from class kotlin.collections.MutableCollection

        contains, containsAll, isEmpty, parallelStream, spliterator, stream, toArray
      • Methods inherited from class kotlin.collections.Collection

        forEach
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • EvictingQueue

        EvictingQueue(Integer maxSize)
        Secondary constructor that initializes the EvictingQueue with the given maxSize.
        Parameters:
        maxSize - the maximum number of elements the queue can hold.
    • Method Detail

      • add

         Boolean add(T element)

        Adds the specified element to the end of this queue.

        If the queue has reached its maximum capacity, the first (oldest) element is evicted (removed) before the new element is added.

        This queue should never throw IllegalStateException due to capacity restriction of the delegate because it uses java.util.Queue.offer to insert elements.

        Parameters:
        element - the element to be added.
      • offer

         Boolean offer(T element)

        Adds the specified element to the end of this queue.

        If the queue has reached its maximum capacity, the first (oldest) element is evicted (removed) before the new element is added.

        Parameters:
        element - the element to be added.
      • addAll

         Boolean addAll(Collection<T> elements)

        Adds all of the elements in the specified elements collection to the end of this queue.

        If the number of elements in elements is greater than or equal to maxSize, the queue is cleared first, and only the last maxSize elements from elements are added.

        Otherwise, if adding elements would exceed the maximum capacity, the required number of oldest elements are evicted from the front of the queue to make room.

        Parameters:
        elements - the collection of elements to be added.