Class BoundedList<T>

All Implemented Interfaces:
Serializable, Iterable<T>, Collection<T>, Queue<T>

public class BoundedList<T> extends ConcurrentLinkedQueue<T>
A bounded subclass of LinkedList, oldest elements are removed once max capacity is exceeded. Note that this class is not synchronized (like LinkedList). Don't use this for high performance, as size() has a linear cost. But in most scenarios, this class is used for maintaining a history, e.g. of digests or views, so perf is not critical.
See Also:
  • Field Details

    • max_capacity

      int max_capacity
  • Constructor Details

    • BoundedList

      public BoundedList()
    • BoundedList

      public BoundedList(int size)
  • Method Details

    • add

      public boolean add(T obj)
      Adds an element at the tail. Removes an object from the head if capacity is exceeded
      Specified by:
      add in interface Collection<T>
      Specified by:
      add in interface Queue<T>
      Overrides:
      add in class ConcurrentLinkedQueue<T>
      Parameters:
      obj - The object to be added
    • addIfAbsent

      public boolean addIfAbsent(T obj)
    • removeFromHead

      public T removeFromHead()