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 -
Method Summary
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.util.Collection
addAll, clear, contains, containsAll, isEmpty, iterator, parallelStream, remove, removeAll, removeIf, retainAll, size, spliterator, stream, toArray, toArray, toArray
-
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
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()Returnstrue
if the buffer is full.- Returns:
true
if the buffer is full.
-
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
- Specified by:
equals
in interfaceCollection<K>
- Overrides:
equals
in classorg.apache.commons.collections4.queue.SynchronizedQueue<K>
-
hashCode
public int hashCode()- Specified by:
hashCode
in interfaceCollection<K>
- Overrides:
hashCode
in classorg.apache.commons.collections4.queue.SynchronizedQueue<K>
-