Home | History | Annotate | Download | only in collection

Lines Matching refs:key

73      * Returns the value for {@code key} if it exists in the cache or can be
78 public final V get(K key) {
79 if (key == null) {
80 throw new NullPointerException("key == null");
85 mapValue = map.get(key);
100 V createdValue = create(key);
107 mapValue = map.put(key, createdValue);
111 map.put(key, mapValue);
113 size += safeSizeOf(key, createdValue);
118 entryRemoved(false, key, createdValue, mapValue);
127 * Caches {@code value} for {@code key}. The value is moved to the head of
130 * @return the previous value mapped by {@code key}.
132 public final V put(K key, V value) {
133 if (key == null || value == null) {
134 throw new NullPointerException("key == null || value == null");
140 size += safeSizeOf(key, value);
141 previous = map.put(key, value);
143 size -= safeSizeOf(key, previous);
148 entryRemoved(false, key, previous, value);
164 K key;
177 key = toEvict.getKey();
179 map.remove(key);
180 size -= safeSizeOf(key, value);
184 entryRemoved(true, key, value, null);
189 * Removes the entry for {@code key} if it exists.
191 * @return the previous value mapped by {@code key}.
193 public final V remove(K key) {
194 if (key == null) {
195 throw new NullPointerException("key == null");
200 previous = map.remove(key);
202 size -= safeSizeOf(key, previous);
207 entryRemoved(false, key, previous, null);
224 * @param newValue the new value for {@code key}, if it exists. If non-null,
228 protected void entryRemoved(boolean evicted, K key, V oldValue, V newValue) {}
231 * Called after a cache miss to compute a value for the corresponding key.
238 * <p>If a value for {@code key} exists in the cache when this method
240 * and discarded. This can occur when multiple threads request the same key
243 * key.
245 protected V create(K key) {
249 private int safeSizeOf(K key, V value) {
250 int result = sizeOf(key, value);
252 throw new IllegalStateException("Negative size: " + key + "=" + value);
258 * Returns the size of the entry for {@code key} and {@code value} in
264 protected int sizeOf(K key, V value) {