(K key, int hash, V value, boolean onlyIfAbsent)
| 2791 | } |
| 2792 | |
| 2793 | @CanIgnoreReturnValue |
| 2794 | @Nullable V put(K key, int hash, V value, boolean onlyIfAbsent) { |
| 2795 | lock(); |
| 2796 | try { |
| 2797 | long now = map.ticker.read(); |
| 2798 | preWriteCleanup(now); |
| 2799 | |
| 2800 | int newCount = this.count + 1; |
| 2801 | if (newCount > this.threshold) { // ensure capacity |
| 2802 | expand(); |
| 2803 | newCount = this.count + 1; |
| 2804 | } |
| 2805 | |
| 2806 | AtomicReferenceArray<ReferenceEntry<K, V>> table = this.table; |
| 2807 | int index = hash & (table.length() - 1); |
| 2808 | ReferenceEntry<K, V> first = table.get(index); |
| 2809 | |
| 2810 | // Look for an existing entry. |
| 2811 | for (ReferenceEntry<K, V> e = first; e != null; e = e.getNext()) { |
| 2812 | K entryKey = e.getKey(); |
| 2813 | if (e.getHash() == hash |
| 2814 | && entryKey != null |
| 2815 | && map.keyEquivalence.equivalent(key, entryKey)) { |
| 2816 | // We found an existing entry. |
| 2817 | |
| 2818 | ValueReference<K, V> valueReference = e.getValueReference(); |
| 2819 | V entryValue = valueReference.get(); |
| 2820 | |
| 2821 | if (entryValue == null) { |
| 2822 | ++modCount; |
| 2823 | if (valueReference.isActive()) { |
| 2824 | enqueueNotification( |
| 2825 | key, hash, entryValue, valueReference.getWeight(), RemovalCause.COLLECTED); |
| 2826 | setValue(e, key, value, now); |
| 2827 | newCount = this.count; // count remains unchanged |
| 2828 | } else { |
| 2829 | setValue(e, key, value, now); |
| 2830 | newCount = this.count + 1; |
| 2831 | } |
| 2832 | this.count = newCount; // write-volatile |
| 2833 | evictEntries(e); |
| 2834 | return null; |
| 2835 | } else if (onlyIfAbsent) { |
| 2836 | // Mimic |
| 2837 | // "if (!map.containsKey(key)) ... |
| 2838 | // else return map.get(key); |
| 2839 | recordLockedRead(e, now); |
| 2840 | return entryValue; |
| 2841 | } else { |
| 2842 | // clobber existing entry, count remains unchanged |
| 2843 | ++modCount; |
| 2844 | enqueueNotification( |
| 2845 | key, hash, entryValue, valueReference.getWeight(), RemovalCause.REPLACED); |
| 2846 | setValue(e, key, value, now); |
| 2847 | evictEntries(e); |
| 2848 | return entryValue; |
| 2849 | } |
| 2850 | } |
nothing calls this directly
no test coverage detected