Lines Matching refs:key

45  *       protected int sizeOf(String key, Bitmap value) {
53 * if (cache.get(key) == null) {
54 * cache.put(key, value);
58 * <p>This class does not allow null to be used as a key or value. A return
60 * unambiguous: the key was not in the cache.
110 * Returns the value for {@code key} if it exists in the cache or can be
115 public final V get(K key) {
116 if (key == null) {
117 throw new NullPointerException("key == null");
122 mapValue = map.get(key);
137 V createdValue = create(key);
144 mapValue = map.put(key, createdValue);
148 map.put(key, mapValue);
150 size += safeSizeOf(key, createdValue);
155 entryRemoved(false, key, createdValue, mapValue);
164 * Caches {@code value} for {@code key}. The value is moved to the head of
167 * @return the previous value mapped by {@code key}.
169 public final V put(K key, V value) {
170 if (key == null || value == null) {
171 throw new NullPointerException("key == null || value == null");
177 size += safeSizeOf(key, value);
178 previous = map.put(key, value);
180 size -= safeSizeOf(key, previous);
185 entryRemoved(false, key, previous, value);
198 K key;
224 key = toEvict.getKey();
226 map.remove(key);
227 size -= safeSizeOf(key, value);
231 entryRemoved(true, key, value, null);
236 * Removes the entry for {@code key} if it exists.
238 * @return the previous value mapped by {@code key}.
240 public final V remove(K key) {
241 if (key == null) {
242 throw new NullPointerException("key == null");
247 previous = map.remove(key);
249 size -= safeSizeOf(key, previous);
254 entryRemoved(false, key, previous, null);
271 * @param newValue the new value for {@code key}, if it exists. If non-null,
275 protected void entryRemoved(boolean evicted, K key, V oldValue, V newValue) {}
278 * Called after a cache miss to compute a value for the corresponding key.
285 * <p>If a value for {@code key} exists in the cache when this method
287 * and discarded. This can occur when multiple threads request the same key
290 * key.
292 protected V create(K key) {
296 private int safeSizeOf(K key, V value) {
297 int result = sizeOf(key, value);
299 throw new IllegalStateException("Negative size: " + key + "=" + value);
305 * Returns the size of the entry for {@code key} and {@code value} in
311 protected int sizeOf(K key, V value) {