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 || !keyEq( key, e.key() ) ) ) { e = e.next; } boolean replaced = false; if ( e != null && oldValue.equals( e.value() ) ) { replaced = true; e.setValue( newValue, valueType, refQueue ); } return replaced; } finally { unlock(); } }
lock(); try { if ( !refRemove ) { removeStale(); && ( refRemove || hash != e.hash || !keyEq( key, e.key() ) ) ) { e = e.next; newFirst = newHashEntry( pKey, p.hash, newFirst, p.value() ); unlock();
newTable[k] = newHashEntry( key, p.hash, n, p.value() );
int c = segments[i].count; mcsum += mc[i] = segments[i].modCount; if ( segments[i].containsValue( value ) ) { return true; segments[i].lock(); if ( segments[i].containsValue( value ) ) { found = true; break; segments[i].unlock();
lock(); try { if ( !refRemove ) { removeStale(); && ( refRemove || hash != e.hash || !keyEq( key, e.key() ) ) ) { e = e.next; newFirst = newHashEntry( pKey, p.hash, newFirst, p.value() ); unlock();
V put(K key, int hash, V value, boolean onlyIfAbsent) { lock(); try { removeStale(); int c = count; if ( c++ > threshold ) {// ensure capacity int reduced = rehash(); if ( reduced > 0 ) { HashEntry<K, V> first = tab[index]; HashEntry<K, V> e = first; while ( e != null && ( e.hash != hash || !keyEq( key, e.key() ) ) ) { e = e.next; oldValue = null; ++modCount; tab[index] = newHashEntry( key, hash, first, value ); unlock();
void clear() { if ( count != 0 ) { lock(); try { HashEntry<K, V>[] tab = table; for ( int i = 0; i < tab.length; i++ ) { tab[i] = null; } ++modCount; // replace the reference queue to avoid unnecessary stale cleanups refQueue = new ReferenceQueue<Object>(); count = 0; // write-volatile } finally { unlock(); } } } }
/** * Tests if the specified object is a key in this table. * * @param key possible key * * @return <tt>true</tt> if and only if the specified object * is a key in this table, as determined by the * <tt>equals</tt> method; <tt>false</tt> otherwise. * * @throws NullPointerException if the specified key is null */ @Override public boolean containsKey(Object key) { if ( key == null ) { return false; } int hash = hashOf( key ); return segmentFor( hash ).containsKey( key, hash ); }
/** * Returns the value to which the specified key is mapped, * or {@code null} if this map contains no mapping for the key. * <p/> * <p>More formally, if this map contains a mapping from a key * {@code k} to a value {@code v} such that {@code key.equals(k)}, * then this method returns {@code v}; otherwise it returns * {@code null}. (There can be at most one such mapping.) * * @throws NullPointerException if the specified key is null */ @Override public V get(Object key) { if ( key == null ) { return null; } int hash = hashOf( key ); return segmentFor( hash ).get( key, hash ); }
/** * 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 || !keyEq( key, e.key() ) ) ) { e = e.next; } V oldValue = null; if ( e != null ) { oldValue = e.value(); e.setValue( newValue, valueType, refQueue ); } return oldValue; } finally { unlock(); } }
V get(Object key, int hash) { if ( count != 0 ) { // read-volatile HashEntry<K, V> e = getFirst( hash ); while ( e != null ) { if ( e.hash == hash && keyEq( key, e.key() ) ) { Object opaque = e.valueRef; if ( opaque != null ) { return e.dereferenceValue( opaque ); } return readValueUnderLock( e ); // recheck } e = e.next; } } return null; }
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 || !keyEq( key, e.key() ) ) ) { e = e.next; } boolean replaced = false; if ( e != null && oldValue.equals( e.value() ) ) { replaced = true; e.setValue( newValue, valueType, refQueue ); } return replaced; } finally { unlock(); } }
/** * Removes all of the mappings from this map. */ @Override public void clear() { for ( int i = 0; i < segments.length; ++i ) { segments[i].clear(); } }
newTable[k] = newHashEntry( key, p.hash, n, p.value() );