Caches value for key. The value is moved to the head of the queue. @return the previous value mapped by key.
(K key, V value)
| 132 | * @return the previous value mapped by {@code key}. |
| 133 | */ |
| 134 | public final V put(K key, V value) { |
| 135 | if (key == null || value == null) { |
| 136 | throw new NullPointerException("key == null || value == null"); |
| 137 | } |
| 138 | |
| 139 | V previous; |
| 140 | synchronized (this) { |
| 141 | putCount++; |
| 142 | size += safeSizeOf(key, value); |
| 143 | previous = map.put(key, value); |
| 144 | if (previous != null) { |
| 145 | size -= safeSizeOf(key, previous); |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | if (previous != null) { |
| 150 | entryRemoved(false, key, previous, value); |
| 151 | } |
| 152 | |
| 153 | trimToSize(maxSize); |
| 154 | return previous; |
| 155 | } |
| 156 | |
| 157 | /** |
| 158 | * Remove the eldest entries until the total of remaining entries is at or |
no test coverage detected