(K key, int hash, V oldValue, V newValue)
| 3058 | } |
| 3059 | |
| 3060 | boolean replace(K key, int hash, V oldValue, V newValue) { |
| 3061 | lock(); |
| 3062 | try { |
| 3063 | long now = map.ticker.read(); |
| 3064 | preWriteCleanup(now); |
| 3065 | AtomicReferenceArray<ReferenceEntry<K, V>> table = this.table; |
| 3066 | int index = hash & (table.length() - 1); |
| 3067 | ReferenceEntry<K, V> first = table.get(index); |
| 3068 | for (ReferenceEntry<K, V> e = first; e != null; e = e.getNext()) { |
| 3069 | K entryKey = e.getKey(); |
| 3070 | if (e.getHash() == hash && entryKey != null |
| 3071 | && map.keyEquivalence.equivalent(key, entryKey)) { |
| 3072 | ValueReference<K, V> valueReference = e.getValueReference(); |
| 3073 | V entryValue = valueReference.get(); |
| 3074 | if (entryValue == null) { |
| 3075 | if (valueReference.isActive()) { |
| 3076 | // If the value disappeared, this entry is partially collected. |
| 3077 | int newCount = this.count - 1; |
| 3078 | ++modCount; |
| 3079 | ReferenceEntry<K, V> newFirst = removeValueFromChain(first, e, entryKey, hash, entryValue, valueReference, RemovalCause.COLLECTED); |
| 3080 | newCount = this.count - 1; |
| 3081 | table.set(index, newFirst); |
| 3082 | this.count = newCount; // write-volatile |
| 3083 | } |
| 3084 | return false; |
| 3085 | } |
| 3086 | if (map.valueEquivalence.equivalent(oldValue, entryValue)) { |
| 3087 | ++modCount; |
| 3088 | enqueueNotification(key, hash, entryValue, valueReference.getWeight(), RemovalCause.REPLACED); |
| 3089 | setValue(e, key, newValue, now); |
| 3090 | evictEntries(e); |
| 3091 | return true; |
| 3092 | } else { |
| 3093 | // Mimic |
| 3094 | // "if (map.containsKey(key) && map.get(key).equals(oldValue))..." |
| 3095 | recordLockedRead(e, now); |
| 3096 | return false; |
| 3097 | } |
| 3098 | } |
| 3099 | } |
| 3100 | return false; |
| 3101 | } finally { |
| 3102 | unlock(); |
| 3103 | postWriteCleanup(); |
| 3104 | } |
| 3105 | } |
| 3106 | |
| 3107 | @Nullable |
| 3108 | V replace(K key, int hash, V newValue) { |
nothing calls this directly
no test coverage detected