Lines Matching refs:key

72      * Returns the value for {@code key} if it exists in the cache or can be
77 public final V get(K key) {
78 if (key == null) {
79 throw new NullPointerException("key == null");
84 mapValue = map.get(key);
99 V createdValue = create(key);
106 mapValue = map.put(key, createdValue);
110 map.put(key, mapValue);
112 size += safeSizeOf(key, createdValue);
117 entryRemoved(false, key, createdValue, mapValue);
126 * Caches {@code value} for {@code key}. The value is moved to the head of
129 * @return the previous value mapped by {@code key}.
131 public final V put(K key, V value) {
132 if (key == null || value == null) {
133 throw new NullPointerException("key == null || value == null");
139 size += safeSizeOf(key, value);
140 previous = map.put(key, value);
142 size -= safeSizeOf(key, previous);
147 entryRemoved(false, key, previous, value);
163 K key;
176 key = toEvict.getKey();
178 map.remove(key);
179 size -= safeSizeOf(key, value);
183 entryRemoved(true, key, value, null);
188 * Removes the entry for {@code key} if it exists.
190 * @return the previous value mapped by {@code key}.
192 public final V remove(K key) {
193 if (key == null) {
194 throw new NullPointerException("key == null");
199 previous = map.remove(key);
201 size -= safeSizeOf(key, previous);
206 entryRemoved(false, key, previous, null);
223 * @param newValue the new value for {@code key}, if it exists. If non-null,
227 protected void entryRemoved(boolean evicted, K key, V oldValue, V newValue) {}
230 * Called after a cache miss to compute a value for the corresponding key.
237 * <p>If a value for {@code key} exists in the cache when this method
239 * and discarded. This can occur when multiple threads request the same key
242 * key.
244 protected V create(K key) {
248 private int safeSizeOf(K key, V value) {
249 int result = sizeOf(key, value);
251 throw new IllegalStateException("Negative size: " + key + "=" + value);
257 * Returns the size of the entry for {@code key} and {@code value} in
263 protected int sizeOf(K key, V value) {