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.
105 * Returns the value for {@code key} if it exists in the cache or can be
110 public final V get(K key) {
111 if (key == null) {
112 throw new NullPointerException("key == null");
117 mapValue = map.get(key);
132 V createdValue = create(key);
139 mapValue = map.put(key, createdValue);
143 map.put(key, mapValue);
145 size += safeSizeOf(key, createdValue);
150 entryRemoved(false, key, createdValue, mapValue);
159 * Caches {@code value} for {@code key}. The value is moved to the head of
162 * @return the previous value mapped by {@code key}.
164 public final V put(K key, V value) {
165 if (key == null || value == null) {
166 throw new NullPointerException("key == null || value == null");
172 size += safeSizeOf(key, value);
173 previous = map.put(key, value);
175 size -= safeSizeOf(key, previous);
180 entryRemoved(false, key, previous, value);
196 K key;
213 key = toEvict.getKey();
215 map.remove(key);
216 size -= safeSizeOf(key, value);
220 entryRemoved(true, key, value, null);
225 * Removes the entry for {@code key} if it exists.
227 * @return the previous value mapped by {@code key}.
229 public final V remove(K key) {
230 if (key == null) {
231 throw new NullPointerException("key == null");
236 previous = map.remove(key);
238 size -= safeSizeOf(key, previous);
243 entryRemoved(false, key, previous, null);
260 * @param newValue the new value for {@code key}, if it exists. If non-null,
264 protected void entryRemoved(boolean evicted, K key, V oldValue, V newValue) {}
267 * Called after a cache miss to compute a value for the corresponding key.
274 * <p>If a value for {@code key} exists in the cache when this method
276 * and discarded. This can occur when multiple threads request the same key
279 * key.
281 protected V create(K key) {
285 private int safeSizeOf(K key, V value) {
286 int result = sizeOf(key, value);
288 throw new IllegalStateException("Negative size: " + key + "=" + value);
294 * Returns the size of the entry for {@code key} and {@code value} in
300 protected int sizeOf(K key, V value) {