An evicting queue must be configured with a maximum size. Each time an element is added to a full queue, the queue automatically removes its head element. This is different from conventional bounded queues, which either block or reject new elements when full.
This class is not thread-safe, and does not accept null elements.
| Modifier and Type | Field and Description |
|---|---|
| private final Queue | |
| pack-priv final int | |
| private static final long |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | Returns: true alwaysthe element to add e)Overrides com. Implements java. |
| public boolean | addAll(Collection<? extends E>
collection containing elements to be added to this collection collection)Overrides com. Implements java. |
| public static <E> EvictingQueue | |
| protected Queue | delegate()
Implements abstract com. |
| public boolean | Returns: true alwaysthe element to add e)Overrides com. Implements java. |
| public int | remainingCapacity()
Returns the number of additional elements that this queue can accept without evicting; zero if the queue is currently full. |
| public Object[] | toArray()
Overrides com. Implements java. |
| delegate | back to summary |
|---|---|
| private final Queue<E> delegate | |
| maxSize | back to summary |
|---|---|
| pack-priv final int maxSize
| |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID | |
| EvictingQueue | back to summary |
|---|---|
| private EvictingQueue(int maxSize) | |
| add | back to summary |
|---|---|
| public boolean add(E e) Overrides com. Implements java. Adds the given element to this queue. If the queue is currently full, the element at the head of the queue is evicted to make room.
| |
| addAll | back to summary |
|---|---|
| public boolean addAll(Collection<? extends E> collection) Overrides com. Implements java. Doc from java. Adds all of the elements in the specified collection to this collection (optional operation). The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (This implies that the behavior of this call is undefined if the specified collection is this collection, and this collection is nonempty.) If the specified collection has a defined encounter order, processing of its elements generally occurs in that order.
| |
| create | back to summary |
|---|---|
| public static <E> EvictingQueue Creates and returns a new evicting queue that will hold up to When | |
| delegate | back to summary |
|---|---|
| protected Queue Implements abstract com. Doc from com. Returns the backing delegate instance that methods are forwarded to. Abstract subclasses
generally override this method with an abstract method that has a more specific return type,
such as
| |
| offer | back to summary |
|---|---|
| public boolean offer(E e) Overrides com. Implements java. Adds the given element to this queue. If the queue is currently full, the element at the head of the queue is evicted to make room.
| |
| remainingCapacity | back to summary |
|---|---|
| public int remainingCapacity() Returns the number of additional elements that this queue can accept without evicting; zero if the queue is currently full.
| |
| toArray | back to summary |
|---|---|
| public Object[] toArray() Overrides com. Implements java. Doc from java. Returns an array containing all of the elements in this collection.
If this collection makes any guarantees as to what order its elements
are returned by its iterator, this method must return the elements in
the same order. The returned array's runtime component type is The returned array will be "safe" in that no references to it are maintained by this collection. (In other words, this method must allocate a new array even if this collection is backed by an array). The caller is thus free to modify the returned array.
| |