Lines Matching refs:key

41  *       protected int sizeOf(String key, Bitmap value) {
49 * if (cache.get(key) == null) {
50 * cache.put(key, value);
54 * <p>This class does not allow null to be used as a key or value. A return
56 * unambiguous: the key was not in the cache.
106 * Returns the value for {@code key} if it exists in the cache or can be
111 public final V get(K key) {
112 if (key == null) {
113 throw new NullPointerException("key == null");
118 mapValue = map.get(key);
133 V createdValue = create(key);
140 mapValue = map.put(key, createdValue);
144 map.put(key, mapValue);
146 size += safeSizeOf(key, createdValue);
151 entryRemoved(false, key, createdValue, mapValue);
160 * Caches {@code value} for {@code key}. The value is moved to the head of
163 * @return the previous value mapped by {@code key}.
165 public final V put(K key, V value) {
166 if (key == null || value == null) {
167 throw new NullPointerException("key == null || value == null");
173 size += safeSizeOf(key, value);
174 previous = map.put(key, value);
176 size -= safeSizeOf(key, previous);
181 entryRemoved(false, key, previous, value);
197 K key;
214 key = toEvict.getKey();
216 map.remove(key);
217 size -= safeSizeOf(key, value);
221 entryRemoved(true, key, value, null);
226 * Removes the entry for {@code key} if it exists.
228 * @return the previous value mapped by {@code key}.
230 public final V remove(K key) {
231 if (key == null) {
232 throw new NullPointerException("key == null");
237 previous = map.remove(key);
239 size -= safeSizeOf(key, previous);
244 entryRemoved(false, key, previous, null);
261 * @param newValue the new value for {@code key}, if it exists. If non-null,
265 protected void entryRemoved(boolean evicted, K key, V oldValue, V newValue) {}
268 * Called after a cache miss to compute a value for the corresponding key.
275 * <p>If a value for {@code key} exists in the cache when this method
277 * and discarded. This can occur when multiple threads request the same key
280 * key.
282 protected V create(K key) {
286 private int safeSizeOf(K key, V value) {
287 int result = sizeOf(key, value);
289 throw new IllegalStateException("Negative size: " + key + "=" + value);
295 * Returns the size of the entry for {@code key} and {@code value} in
301 protected int sizeOf(K key, V value) {