T - type of objects stored@NotThreadSafe public class EvictingRingBuffer<T> extends AbstractCollection<T> implements Queue<T>, RandomAccess, Cloneable, Serializable
| Modifier | Constructor and Description |
|---|---|
|
EvictingRingBuffer(int capacity) |
|
EvictingRingBuffer(int capacity,
boolean throwOnOverflow) |
|
EvictingRingBuffer(int capacity,
boolean throwOnOverflow,
T defaultValue) |
protected |
EvictingRingBuffer(int capacity,
boolean throwOnOverflow,
T defaultValue,
boolean preFill) |
|
EvictingRingBuffer(int capacity,
T defaultValue) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(T value)
Add a value at the end of the ring buffer.
|
int |
capacity()
Returns buffer capacity (i.e.
|
Object |
clone() |
T |
element()
Retrieves, but does not remove, the head of this buffer.
|
boolean |
equals(Object obj) |
T |
get(int index)
Return the element at the specified position in the buffer.
|
int |
hashCode() |
Iterator<T> |
iterator() |
boolean |
offer(T value)
Inserts the specified element into this queue if it is possible to do so
immediately without violating capacity restrictions.
|
T |
peek()
Retrieves, but does not remove, the head of this buffer, or returns null if empty.
|
T |
poll()
Retrieves and removes the head of this buffer, or returns null if empty.
|
T |
remove()
Retrieves and removes the head of this buffer.
|
int |
size()
Returns number of elements in the buffer.
|
Object[] |
toArray() |
List<T> |
toList()
Returns a
List<T> containing all the elements in the buffer
in proper sequence (first to last element). |
addAll, clear, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toStringfinalize, getClass, notify, notifyAll, wait, wait, waitaddAll, clear, contains, containsAll, isEmpty, parallelStream, remove, removeAll, removeIf, retainAll, spliterator, stream, toArraypublic EvictingRingBuffer(int capacity)
capacity - desired capacity.public EvictingRingBuffer(int capacity,
boolean throwOnOverflow)
capacity - desired capacitythrowOnOverflow - Disables auto-eviction on overflow. When full capacity is
reached, all subsequent append() operations would throw
IllegalStateException if this parameter is true,
or evict the oldest value if this parameter is false.public EvictingRingBuffer(int capacity,
@Nullable
T defaultValue)
capacity - desired capacity.defaultValue - pre-fill the buffer with this default value.public EvictingRingBuffer(int capacity,
boolean throwOnOverflow,
@Nullable
T defaultValue)
capacity - desired capacity.throwOnOverflow - disables auto-eviction on overflow. When full capacity is
reached, all subsequent append() operations would throw
IllegalStateException if this parameter is true,
or evict the oldest value if this parameter is false.defaultValue - pre-fill the buffer with this default value.public int capacity()
@Nonnull public Iterator<T> iterator()
iterator in interface Iterable<T>iterator in interface Collection<T>iterator in class AbstractCollection<T>public int size()
size in interface Collection<T>size in class AbstractCollection<T>public T get(int index)
index - index of the element to returnIndexOutOfBoundsException - if the index is out of range
(index < 0 || index >= size())public boolean add(T value)
add in interface Collection<T>add in interface Queue<T>add in class AbstractCollection<T>value - element to be appended to the end of the bufferCollection#add(T))IllegalStateException - if the element cannot be added at this
time due to capacity restrictionspublic boolean offer(T value)
public List<T> toList()
List<T> containing all the elements in the buffer
in proper sequence (first to last element).List<T> containing all the elements in the buffer
in proper sequence@Nonnull public Object[] toArray()
toArray in interface Collection<T>toArray in class AbstractCollection<T>public T remove()
remove in interface Queue<T>NoSuchElementException - if buffer is emptypublic T poll()
public T element()
public T peek()
public int hashCode()
hashCode in interface Collection<T>hashCode in class Objectpublic boolean equals(Object obj)
equals in interface Collection<T>equals in class Objectpublic Object clone() throws CloneNotSupportedException
clone in class ObjectCloneNotSupportedExceptionCopyright © 2020. All rights reserved.