in src/main/java/org/apache/commons/collections4/map/ConcurrentReferenceHashMap.java [892:929]
private V putInternal(final K key, final int hash, final V value, final Function<? super K, ? extends V> function, final boolean onlyIfAbsent) {
removeStale();
int c = count;
// ensure capacity
if (c++ > threshold) {
final int reduced = rehash();
// adjust from possible weak cleanups
if (reduced > 0) {
// write-volatile
count = (c -= reduced) - 1;
}
}
final HashEntry<K, V>[] tab = table;
final int index = hash & tab.length - 1;
final HashEntry<K, V> first = tab[index];
HashEntry<K, V> e = first;
while (e != null && (e.hash != hash || !keyEq(key, e.key()))) {
e = e.next;
}
final V resultValue;
if (e != null) {
resultValue = e.value();
if (!onlyIfAbsent) {
e.setValue(getValue(key, value, function), valueType, refQueue);
}
} else {
final V v = getValue(key, value, function);
resultValue = function != null ? v : null;
if (v != null) {
++modCount;
tab[index] = newHashEntry(key, hash, first, v);
// write-volatile
count = c;
}
}
return resultValue;
}