/** * This is used to determine if an entry should be removed from the cache. If the cache has * reached its capacity then the listener, if one was specified is given a callback to tell any * other participating objects the entry has been removed. * * @param eldest this is the candidate for removal */ @Override protected boolean removeEldestEntry(Entry<K, V> eldest) { int size = size(); if (size <= capacity) { return false; } if (listener != null) { V value = eldest.getValue(); K key = eldest.getKey(); listener.notifyRemoved(key, value); } return true; }
@SuppressWarnings("unchecked") @Override public synchronized V remove(Object key) { removalListener.onRemoval((K) key, get(key)); return super.remove(key); }