/** * @return The next element in this queue, or {@code null} if the queue is * empty. */ public LruCachedBlock poll() { return queue.poll(); }
/** * @return The next element in this queue, or {@code null} if the queue is * empty. */ public Map.Entry<BlockCacheKey, BucketEntry> poll() { return queue.poll(); }
/** * Attempt to add the specified entry to this queue. * <p> * If the queue is smaller than the max size, or if the specified element is * ordered after the smallest element in the queue, the element will be added * to the queue. Otherwise, there is no side effect of this call. * @param entry a bucket entry with key to try to add to the queue */ public void add(Map.Entry<BlockCacheKey, BucketEntry> entry) { if (cacheSize < maxSize) { queue.add(entry); cacheSize += entry.getValue().getLength(); } else { BucketEntry head = queue.peek().getValue(); if (BucketEntry.COMPARATOR.compare(entry.getValue(), head) > 0) { cacheSize += entry.getValue().getLength(); cacheSize -= head.getLength(); if (cacheSize > maxSize) { queue.poll(); } else { cacheSize += head.getLength(); } queue.add(entry); } } }
/** * Attempt to add the specified cached block to this queue. * * <p>If the queue is smaller than the max size, or if the specified element * is ordered before the smallest element in the queue, the element will be * added to the queue. Otherwise, there is no side effect of this call. * @param cb block to try to add to the queue */ public void add(LruCachedBlock cb) { if(heapSize < maxSize) { queue.add(cb); heapSize += cb.heapSize(); } else { LruCachedBlock head = queue.peek(); if(cb.compareTo(head) > 0) { heapSize += cb.heapSize(); heapSize -= head.heapSize(); if(heapSize > maxSize) { queue.poll(); } else { heapSize += head.heapSize(); } queue.add(cb); } } }
/** * Removes and returns the least element of this queue, or returns {@code * null} if the queue is empty. */ @CanIgnoreReturnValue public E pollFirst() { return poll(); }