Class RingBuffer<K>

java.lang.Object
org.apache.commons.collections4.collection.SynchronizedCollection<E>
org.apache.commons.collections4.queue.SynchronizedQueue<K>
io.aiven.kafka.connect.common.source.RingBuffer<K>
Type Parameters:
K - the type of item in the queue. Must support equality check.
All Implemented Interfaces:
Serializable, Iterable<K>, Collection<K>, Queue<K>

public final class RingBuffer<K> extends org.apache.commons.collections4.queue.SynchronizedQueue<K>
Implements a ring buffer of items.
See Also:
  • Field Summary

    Fields inherited from class org.apache.commons.collections4.collection.SynchronizedCollection

    lock
  • Constructor Summary

    Constructors
    Constructor
    Description
    RingBuffer(int size)
    Create a Ring Buffer of a maximum Size.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    enqueue(K item)
    Adds a new item if it is not already present.
    boolean
    equals(Object object)
     
    Get the last value in the Ring buffer
    int
     
    boolean
    Returns true if the buffer is full.

    Methods inherited from class org.apache.commons.collections4.queue.SynchronizedQueue

    decorated, element, offer, peek, poll, remove, synchronizedQueue

    Methods inherited from class org.apache.commons.collections4.collection.SynchronizedCollection

    add, addAll, clear, contains, containsAll, isEmpty, iterator, remove, removeAll, removeIf, retainAll, size, synchronizedCollection, toArray, toArray, toString

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface java.lang.Iterable

    forEach

    Methods inherited from interface java.util.Queue

    add
  • Constructor Details

    • RingBuffer

      public RingBuffer(int size)
      Create a Ring Buffer of a maximum Size. If the size is less than or equal to 0 then the buffer is always empty.
      Parameters:
      size - The size that the linked list should be.
  • Method Details

    • enqueue

      public void enqueue(K item)
      Adds a new item if it is not already present.
      • If the buffer is always empty the item is ignored and not enqueued.
      • If the buffer already contains the item it is ignored and not enqueued.
      • If the buffer is full the oldest entry in the list is removed.
      Parameters:
      item - Item T which is to be added to the Queue
    • isFull

      public boolean isFull()
      Returns true if the buffer is full.
      Returns:
      true if the buffer is full.
    • getOldest

      public K getOldest()
      Get the last value in the Ring buffer
      Returns:
      A value T from the last place in the list, returns null if list is not full.
    • equals

      public boolean equals(Object object)
      Specified by:
      equals in interface Collection<K>
      Overrides:
      equals in class org.apache.commons.collections4.queue.SynchronizedQueue<K>
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in interface Collection<K>
      Overrides:
      hashCode in class org.apache.commons.collections4.queue.SynchronizedQueue<K>