MCPcopy Create free account
hub / github.com/antlr/codebuff / replace

Method replace

output/java_guava/1.4.16/LocalCache.java:3060–3105  ·  view source on GitHub ↗
(K key, int hash, V oldValue, V newValue)

Source from the content-addressed store, hash-verified

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) {

Callers

nothing calls this directly

Calls 15

preWriteCleanupMethod · 0.95
removeValueFromChainMethod · 0.95
enqueueNotificationMethod · 0.95
setValueMethod · 0.95
evictEntriesMethod · 0.95
recordLockedReadMethod · 0.95
postWriteCleanupMethod · 0.95
getMethod · 0.65
getNextMethod · 0.65
getKeyMethod · 0.65
getHashMethod · 0.65
getValueReferenceMethod · 0.65

Tested by

no test coverage detected