Class LimitedQueue<K>

  • Type Parameters:
    K -
    All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<K>, java.util.Collection<K>, java.util.List<K>, java.util.RandomAccess

    public class LimitedQueue<K>
    extends java.util.ArrayList<K>
    A data structure that is limited in size and otherwise works as a queue (but can also access the latest/youngest element at the tail)
    Author:
    Andreas Rogge-Solti
    See Also:
    Serialized Form
    • Field Summary

      • Fields inherited from class java.util.AbstractList

        modCount
    • Constructor Summary

      Constructors 
      Constructor Description
      LimitedQueue​(int size)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(K k)  
      boolean addAll​(int index, java.util.Collection<? extends K> c)  
      boolean addAll​(java.util.Collection<? extends K> c)  
      K getLast()
      Provides access to the element inserted as last (the youngest element in the queue)
      protected boolean limitSize()  
      K peek()
      Takes a peek at the element, which is the oldest one in the queue without removing it.
      K poll()
      Removes the oldest element in the list (FIFO)
      • Methods inherited from class java.util.ArrayList

        add, clear, clone, contains, ensureCapacity, equals, forEach, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeIf, removeRange, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray, trimToSize
      • Methods inherited from class java.util.AbstractCollection

        containsAll, toString
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Collection

        parallelStream, stream, toArray
      • Methods inherited from interface java.util.List

        containsAll
    • Constructor Detail

      • LimitedQueue

        public LimitedQueue​(int size)
    • Method Detail

      • add

        public boolean add​(K k)
        Specified by:
        add in interface java.util.Collection<K>
        Specified by:
        add in interface java.util.List<K>
        Overrides:
        add in class java.util.ArrayList<K>
      • addAll

        public boolean addAll​(java.util.Collection<? extends K> c)
        Specified by:
        addAll in interface java.util.Collection<K>
        Specified by:
        addAll in interface java.util.List<K>
        Overrides:
        addAll in class java.util.ArrayList<K>
      • limitSize

        protected boolean limitSize()
        Returns:
        boolean indicating whether the list changed
      • addAll

        public boolean addAll​(int index,
                              java.util.Collection<? extends K> c)
        Specified by:
        addAll in interface java.util.List<K>
        Overrides:
        addAll in class java.util.ArrayList<K>
      • getLast

        public K getLast()
        Provides access to the element inserted as last (the youngest element in the queue)
        Returns:
        K
      • peek

        public K peek()
        Takes a peek at the element, which is the oldest one in the queue without removing it.
        Returns:
      • poll

        public K poll()
        Removes the oldest element in the list (FIFO)
        Returns:
        K the oldest element that is also removed