Lines Matching refs:key

56      * Returns the value for {@code key} if it exists in the cache or can be
61 public final V get(K key) {
62 if (key == null) {
63 throw new NullPointerException("key == null");
68 mapValue = map.get(key);
83 V createdValue = create(key);
90 mapValue = map.put(key, createdValue);
94 map.put(key, mapValue);
96 size += safeSizeOf(key, createdValue);
101 entryRemoved(false, key, createdValue, mapValue);
110 * Caches {@code value} for {@code key}. The value is moved to the head of
113 * @return the previous value mapped by {@code key}.
115 public final V put(K key, V value) {
116 if (key == null || value == null) {
117 throw new NullPointerException("key == null || value == null");
123 size += safeSizeOf(key, value);
124 previous = map.put(key, value);
126 size -= safeSizeOf(key, previous);
131 entryRemoved(false, key, previous, value);
147 K key;
160 key = toEvict.getKey();
162 map.remove(key);
163 size -= safeSizeOf(key, value);
167 entryRemoved(true, key, value, null);
172 * Removes the entry for {@code key} if it exists.
174 * @return the previous value mapped by {@code key}.
176 public final V remove(K key) {
177 if (key == null) {
178 throw new NullPointerException("key == null");
183 previous = map.remove(key);
185 size -= safeSizeOf(key, previous);
190 entryRemoved(false, key, previous, null);
207 * @param newValue the new value for {@code key}, if it exists. If non-null,
211 protected void entryRemoved(boolean evicted, K key, V oldValue, V newValue) {}
214 * Called after a cache miss to compute a value for the corresponding key.
221 * <p>If a value for {@code key} exists in the cache when this method
223 * and discarded. This can occur when multiple threads request the same key
226 * key.
228 protected V create(K key) {
232 private int safeSizeOf(K key, V value) {
233 int result = sizeOf(key, value);
235 throw new IllegalStateException("Negative size: " + key + "=" + value);
241 * Returns the size of the entry for {@code key} and {@code value} in
247 protected int sizeOf(K key, V value) {