(K key, int hash, V oldValue, V newValue)
| 2936 | } |
| 2937 | |
| 2938 | boolean replace(K key, int hash, V oldValue, V newValue) { |
| 2939 | lock(); |
| 2940 | try { |
| 2941 | long now = map.ticker.read(); |
| 2942 | preWriteCleanup(now); |
| 2943 | |
| 2944 | AtomicReferenceArray<ReferenceEntry<K, V>> table = this.table; |
| 2945 | int index = hash & (table.length() - 1); |
| 2946 | ReferenceEntry<K, V> first = table.get(index); |
| 2947 | |
| 2948 | for (ReferenceEntry<K, V> e = first; e != null; e = e.getNext()) { |
| 2949 | K entryKey = e.getKey(); |
| 2950 | if (e.getHash() == hash |
| 2951 | && entryKey != null |
| 2952 | && map.keyEquivalence.equivalent(key, entryKey)) { |
| 2953 | ValueReference<K, V> valueReference = e.getValueReference(); |
| 2954 | V entryValue = valueReference.get(); |
| 2955 | if (entryValue == null) { |
| 2956 | if (valueReference.isActive()) { |
| 2957 | // If the value disappeared, this entry is partially collected. |
| 2958 | int newCount = this.count - 1; |
| 2959 | ++modCount; |
| 2960 | ReferenceEntry<K, V> newFirst = |
| 2961 | removeValueFromChain( |
| 2962 | first, |
| 2963 | e, |
| 2964 | entryKey, |
| 2965 | hash, |
| 2966 | entryValue, |
| 2967 | valueReference, |
| 2968 | RemovalCause.COLLECTED); |
| 2969 | newCount = this.count - 1; |
| 2970 | table.set(index, newFirst); |
| 2971 | this.count = newCount; // write-volatile |
| 2972 | } |
| 2973 | return false; |
| 2974 | } |
| 2975 | |
| 2976 | if (map.valueEquivalence.equivalent(oldValue, entryValue)) { |
| 2977 | ++modCount; |
| 2978 | enqueueNotification( |
| 2979 | key, hash, entryValue, valueReference.getWeight(), RemovalCause.REPLACED); |
| 2980 | setValue(e, key, newValue, now); |
| 2981 | evictEntries(e); |
| 2982 | return true; |
| 2983 | } else { |
| 2984 | // Mimic |
| 2985 | // "if (map.containsKey(key) && map.get(key).equals(oldValue))..." |
| 2986 | recordLockedRead(e, now); |
| 2987 | return false; |
| 2988 | } |
| 2989 | } |
| 2990 | } |
| 2991 | |
| 2992 | return false; |
| 2993 | } finally { |
| 2994 | unlock(); |
| 2995 | postWriteCleanup(); |
nothing calls this directly
no test coverage detected