boolean containsKey(Object key, int hash) { if ( count != 0 ) { // read-volatile HashEntry<K, V> e = getFirst( hash ); while ( e != null ) { if ( e.hash == hash && key.equals( e.key ) ) { return true; } e = e.next; } } return false; }
boolean replace(K key, int hash, V oldValue, V newValue) { lock(); Set<HashEntry<K, V>> evicted = null; try { HashEntry<K, V> e = getFirst( hash ); while ( e != null && ( e.hash != hash || !key.equals( e.key ) ) ) { e = e.next; } boolean replaced = false; if ( e != null && oldValue.equals( e.value ) ) { replaced = true; e.value = newValue; if ( eviction.onEntryHit( e ) ) { evicted = attemptEviction( true ); } } return replaced; } finally { unlock(); notifyEvictionListener( evicted ); } }
V get(Object key, int hash) { int c = count; if ( c != 0 ) { // read-volatile V result = null; HashEntry<K, V> e = getFirst( hash ); while ( e != null ) { if ( e.hash == hash && key.equals( e.key ) ) { V v = e.value; if ( v != null ) { result = v; break; } else { result = readValueUnderLock( e ); // recheck break; } } e = e.next; } // a hit if ( result != null ) { if ( eviction.onEntryHit( e ) ) { Set<HashEntry<K, V>> evicted = attemptEviction( false ); notifyEvictionListener( evicted ); } } return result; } return null; }
V get(Object key, int hash) { int c = count; if ( c != 0 ) { // read-volatile V result = null; HashEntry<K, V> e = getFirst( hash ); while ( e != null ) { if ( e.hash == hash && key.equals( e.key ) ) { V v = e.value; if ( v != null ) { result = v; break; } else { result = readValueUnderLock( e ); // recheck break; } } e = e.next; } // a hit if ( result != null ) { if ( eviction.onEntryHit( e ) ) { Set<HashEntry<K, V>> evicted = attemptEviction( false ); notifyEvictionListener( evicted ); } } return result; } return null; }
V replace(K key, int hash, V newValue) { lock(); Set<HashEntry<K, V>> evicted = null; try { HashEntry<K, V> e = getFirst( hash ); while ( e != null && ( e.hash != hash || !key.equals( e.key ) ) ) { e = e.next; } V oldValue = null; if ( e != null ) { oldValue = e.value; e.value = newValue; if ( eviction.onEntryHit( e ) ) { evicted = attemptEviction( true ); } } return oldValue; } finally { unlock(); notifyEvictionListener( evicted ); } }
boolean replace(K key, int hash, V oldValue, V newValue) { lock(); Set<HashEntry<K, V>> evicted = null; try { HashEntry<K, V> e = getFirst( hash ); while ( e != null && ( e.hash != hash || !key.equals( e.key ) ) ) { e = e.next; } boolean replaced = false; if ( e != null && oldValue.equals( e.value ) ) { replaced = true; e.value = newValue; if ( eviction.onEntryHit( e ) ) { evicted = attemptEviction( true ); } } return replaced; } finally { unlock(); notifyEvictionListener( evicted ); } }
boolean containsKey(Object key, int hash) { if ( count != 0 ) { // read-volatile HashEntry<K, V> e = getFirst( hash ); while ( e != null ) { if ( e.hash == hash && key.equals( e.key ) ) { return true; } e = e.next; } } return false; }
V replace(K key, int hash, V newValue) { lock(); Set<HashEntry<K, V>> evicted = null; try { HashEntry<K, V> e = getFirst( hash ); while ( e != null && ( e.hash != hash || !key.equals( e.key ) ) ) { e = e.next; } V oldValue = null; if ( e != null ) { oldValue = e.value; e.value = newValue; if ( eviction.onEntryHit( e ) ) { evicted = attemptEviction( true ); } } return oldValue; } finally { unlock(); notifyEvictionListener( evicted ); } }