Class CellsQueue<T,C extends Cell<T>>

All Implemented Interfaces:
Serializable, Cloneable, Iterable<C>, Collection<C>, Deque<C>, List<C>, Queue<C>, SequencedCollection<C>

public class CellsQueue<T,C extends Cell<T>> extends LinkedList<C>
A special kind of LinkedList which discards the oldest added item once it reaches the set capacity.

Basically the same as CircularQueue, but automatically invokes Cell.dispose() on cell that are discarded.

See Also:
  • Constructor Details

    • CellsQueue

      public CellsQueue(int capacity)
  • Method Details

    • queue

      public boolean queue(C c)
      Adds the given cell to the queue. If at capacity, the oldest cell is disposed and discarded.
      Returns:
      whether the cell was added
    • getCapacity

      public int getCapacity()
      Returns:
      the queue's capacity, the maximum number of cells that can be added
    • setCapacity

      public void setCapacity(int capacity)
      Sets the queue's capacity. If the parameter is 0, every cell is disposed and removed. If the new capacity is lesser than the current one, then the oldest cell is removed until the capacity is reached.
    • add

      public boolean add(C c)
      Specified by:
      add in interface Collection<T>
      Specified by:
      add in interface Deque<T>
      Specified by:
      add in interface List<T>
      Specified by:
      add in interface Queue<T>
      Overrides:
      add in class LinkedList<C extends Cell<T>>
    • addAll

      public boolean addAll(Collection<? extends C> cells)
      Specified by:
      addAll in interface Collection<T>
      Specified by:
      addAll in interface Deque<T>
      Specified by:
      addAll in interface List<T>
      Overrides:
      addAll in class LinkedList<C extends Cell<T>>