/** * Returns the number of additional elements that this queue can accept without evicting; * zero if the queue is currently full. * * @since 16.0 */ public int remainingCapacity() { return maxSize - size(); }
/** * 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. * * @return {@code true} always */ @Override public boolean add(E e) { checkNotNull(e); // check before removing if (maxSize == 0) { return true; } if (size() == maxSize) { delegate.remove(); } delegate.add(e); return true; }