@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null || getClass() != obj.getClass()) { return false; } LruCachedBlock other = (LruCachedBlock) obj; return compareTo(other) == 0; }
/** * 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); } } }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null || getClass() != obj.getClass()) { return false; } LruCachedBlock other = (LruCachedBlock) obj; return compareTo(other) == 0; }
/** * 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); } } }