Package org.utils.datastructures
Class LimitedQueue<K>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<E>
-
- java.util.ArrayList<K>
-
- org.utils.datastructures.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
-
-
Constructor Summary
Constructors Constructor Description LimitedQueue(int size)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(K k)booleanaddAll(int index, java.util.Collection<? extends K> c)booleanaddAll(java.util.Collection<? extends K> c)KgetLast()Provides access to the element inserted as last (the youngest element in the queue)protected booleanlimitSize()Kpeek()Takes a peek at the element, which is the oldest one in the queue without removing it.Kpoll()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
-
-
-
-
Method Detail
-
add
public boolean add(K k)
-
addAll
public boolean addAll(java.util.Collection<? extends K> c)
-
limitSize
protected boolean limitSize()
- Returns:
- boolean indicating whether the list changed
-
addAll
public boolean addAll(int index, java.util.Collection<? extends K> c)
-
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
-
-