Class CircularFifoBuffer

All Implemented Interfaces:
Serializable, Iterable, Collection, BoundedCollection, Buffer

@Deprecated(since="2021-04-30") public class CircularFifoBuffer extends BoundedFifoBuffer
Deprecated.
Apache Commons Collections version 3.x is being deprecated from AEMaaCS. The upgraded version 4.4 of Commons Collections is already included as replacement. Customers are advised to upgrade to this version of the library. Please note: the package name was changed to org.apache.commons.collections4. Further note that there are AEM APIs currently exposing the old collections classes; these will be updated in upcoming releases.
CircularFifoBuffer is a first in first out buffer with a fixed size that replaces its oldest element if full.

The removal order of a CircularFifoBuffer is based on the insertion order; elements are removed in the same order in which they were added. The iteration order is the same as the removal order.

The add(Object), BoundedFifoBuffer.remove() and BoundedFifoBuffer.get() operations all perform in constant time. All other operations perform in linear time or worse.

Note that this implementation is not synchronized. The following can be used to provide synchronized access to your CircularFifoBuffer:

    Buffer fifo = BufferUtils.synchronizedBuffer(new CircularFifoBuffer());
  

This buffer prevents null objects from being added.

This class is Serializable from Commons Collections 3.1.

Since:
Commons Collections 3.0
See Also:
  • Constructor Details

    • CircularFifoBuffer

      public CircularFifoBuffer()
      Deprecated.
      Constructor that creates a buffer with the default size of 32.
    • CircularFifoBuffer

      public CircularFifoBuffer(int size)
      Deprecated.
      Constructor that creates a buffer with the specified size.
      Parameters:
      size - the size of the buffer (cannot be changed)
      Throws:
      IllegalArgumentException - if the size is less than 1
    • CircularFifoBuffer

      public CircularFifoBuffer(Collection coll)
      Deprecated.
      Constructor that creates a buffer from the specified collection. The collection size also sets the buffer size
      Parameters:
      coll - the collection to copy into the buffer, may not be null
      Throws:
      NullPointerException - if the collection is null
  • Method Details

    • add

      public boolean add(Object element)
      Deprecated.
      If the buffer is full, the least recently added element is discarded so that a new element can be inserted.
      Specified by:
      add in interface Collection
      Overrides:
      add in class BoundedFifoBuffer
      Parameters:
      element - the element to add
      Returns:
      true, always