(K key, int hash, V oldValue, V newValue)
| 3005 | } |
| 3006 | |
| 3007 | boolean replace(K key, int hash, V oldValue, V newValue) { |
| 3008 | lock(); |
| 3009 | try { |
| 3010 | long now = map.ticker.read(); |
| 3011 | preWriteCleanup(now); |
| 3012 | |
| 3013 | AtomicReferenceArray<ReferenceEntry<K, V>> table = this.table; |
| 3014 | int index = hash & (table.length() - 1); |
| 3015 | ReferenceEntry<K, V> first = table.get(index); |
| 3016 | |
| 3017 | for (ReferenceEntry<K, V> e = first; e != null; e = e.getNext()) { |
| 3018 | K entryKey = e.getKey(); |
| 3019 | if (e.getHash() == hash |
| 3020 | && entryKey != null |
| 3021 | && map.keyEquivalence.equivalent(key, entryKey)) { |
| 3022 | ValueReference<K, V> valueReference = e.getValueReference(); |
| 3023 | V entryValue = valueReference.get(); |
| 3024 | if (entryValue == null) { |
| 3025 | if (valueReference.isActive()) { |
| 3026 | // If the value disappeared, this entry is partially collected. |
| 3027 | int newCount = this.count - 1; |
| 3028 | ++modCount; |
| 3029 | ReferenceEntry<K, V> newFirst = |
| 3030 | removeValueFromChain( |
| 3031 | first, |
| 3032 | e, |
| 3033 | entryKey, |
| 3034 | hash, |
| 3035 | entryValue, |
| 3036 | valueReference, |
| 3037 | RemovalCause.COLLECTED); |
| 3038 | newCount = this.count - 1; |
| 3039 | table.set(index, newFirst); |
| 3040 | this.count = newCount; // write-volatile |
| 3041 | } |
| 3042 | return false; |
| 3043 | } |
| 3044 | |
| 3045 | if (map.valueEquivalence.equivalent(oldValue, entryValue)) { |
| 3046 | ++modCount; |
| 3047 | enqueueNotification( |
| 3048 | key, hash, entryValue, valueReference.getWeight(), RemovalCause.REPLACED); |
| 3049 | setValue(e, key, newValue, now); |
| 3050 | evictEntries(e); |
| 3051 | return true; |
| 3052 | } else { |
| 3053 | // Mimic |
| 3054 | // "if (map.containsKey(key) && map.get(key).equals(oldValue))..." |
| 3055 | recordLockedRead(e, now); |
| 3056 | return false; |
| 3057 | } |
| 3058 | } |
| 3059 | } |
| 3060 | |
| 3061 | return false; |
| 3062 | } finally { |
| 3063 | unlock(); |
| 3064 | postWriteCleanup(); |
nothing calls this directly
no test coverage detected