boolean replace(K key, int hash, V oldValue, V newValue) { lock(); try { removeStale(); HashEntry<K, V> e = getFirst(hash); while(e != null && (e.hash != hash || !key.equals(e.keyRef.get()))) e = e.next; boolean replaced = false; if(e != null && oldValue.equals(e.value)) { replaced = true; e.value = newValue; } return replaced; } finally { unlock(); } }
boolean replace(K key, int hash, V oldValue, V newValue) { lock(); try { removeStale(); HashEntry<K, V> e = getFirst(hash); while(e != null && (e.hash != hash || !key.equals(e.keyRef.get()))) e = e.next; boolean replaced = false; if(e != null && oldValue.equals(e.value)) { replaced = true; e.value = newValue; } return replaced; } finally { unlock(); } }
try { if(!weakRemove) removeStale(); int c = count - 1; HashEntry<K, V>[] tab = table;
try { if(!weakRemove) removeStale(); int c = count - 1; HashEntry<K, V>[] tab = table;
V put(K key, int hash, V value, boolean onlyIfAbsent) { lock(); try { removeStale(); int c = count; if(c++ > threshold) {// ensure capacity
V put(K key, int hash, V value, boolean onlyIfAbsent) { lock(); try { removeStale(); int c = count; if(c++ > threshold) {// ensure capacity
V replace(K key, int hash, V newValue) { lock(); try { removeStale(); HashEntry<K, V> e = getFirst(hash); while(e != null && (e.hash != hash || !key.equals(e.keyRef.get()))) e = e.next; V oldValue = null; if(e != null) { oldValue = e.value; e.value = newValue; } return oldValue; } finally { unlock(); } }
/** * Reads value field of an entry under lock. Called if value * field ever appears to be null. This is possible only if a * compiler happens to reorder a HashEntry initialization with * its table assignment, which is legal under memory model * but is not known to ever occur. */ V readValueUnderLock(HashEntry<K, V> e) { lock(); try { removeStale(); return e.value; } finally { unlock(); } }
V replace(K key, int hash, V newValue) { lock(); try { removeStale(); HashEntry<K, V> e = getFirst(hash); while(e != null && (e.hash != hash || !key.equals(e.keyRef.get()))) e = e.next; V oldValue = null; if(e != null) { oldValue = e.value; e.value = newValue; } return oldValue; } finally { unlock(); } }
/** * Reads value field of an entry under lock. Called if value * field ever appears to be null. This is possible only if a * compiler happens to reorder a HashEntry initialization with * its table assignment, which is legal under memory model * but is not known to ever occur. */ V readValueUnderLock(HashEntry<K, V> e) { lock(); try { removeStale(); return e.value; } finally { unlock(); } }