/** * Returns the value to which this map maps the specified key. Returns {@code null} if the map * contains no mapping for this key. * * @param key Key whose associated value is to be returned. * @return The value to which this map maps the specified key. * @throws NullPointerException if the key is {@code null}. */ @Override public synchronized V get(final Object key) { assert WeakCollectionCleaner.DEFAULT.isAlive(); assert valid() : count; final int index = (key.hashCode() & 0x7FFFFFFF) % table.length; for (Entry e = table[index]; e != null; e = e.next) { if (key.equals(e.key)) { return e.get(); } } return null; }
/** * Stops the cleaner thread. Calling this method is recommended in all long running applications * with custom class loaders (e.g., web applications). */ public void exit() { // try to stop it gracefully synchronized (this) { referenceQueue = null; } this.interrupt(); try { this.join(500); } catch (InterruptedException e) { } // last resort tentative to kill the cleaner thread if (this.isAlive()) this.stop(); } }
final <T extends E> T intern(final T obj, final int operation) { assert Thread.holdsLock(this); assert WeakCollectionCleaner.DEFAULT.isAlive(); assert valid() : count; if (obj != null) {
/** Implementation of {@link #put} and {@link #remove} operations. */ private synchronized V intern(final K key, final V value) { assert WeakCollectionCleaner.DEFAULT.isAlive(); assert valid() : count; /* * Check if {@code obj} is already contained in this * {@code WeakValueHashMap}. If yes, clear it. */ V oldValue = null; final int hash = key.hashCode() & 0x7FFFFFFF; int index = hash % table.length; for (Entry e = table[index]; e != null; e = e.next) { if (key.equals(e.key)) { oldValue = e.get(); e.clear(); } } if (value != null) { if (count >= threshold) { rehash(true); } index = hash % table.length; table[index] = new Entry(key, value, table[index], index); count++; } assert valid(); return oldValue; }
/** * Returns the value to which this map maps the specified key. Returns * {@code null} if the map contains no mapping for this key. * * @param key Key whose associated value is to be returned. * @return The value to which this map maps the specified key. * @throws NullPointerException if the key is {@code null}. */ public synchronized Object get(final Object key) { assert WeakCollectionCleaner.DEFAULT.isAlive(); assert valid() : count; final int index = (key.hashCode() & 0x7FFFFFFF) % table.length; for (Entry e=table[index]; e!=null; e=e.next) { if (key.equals(e.key)) { return e.get(); } } return null; }
/** * Returns the value to which this map maps the specified key. Returns * {@code null} if the map contains no mapping for this key. * * @param key Key whose associated value is to be returned. * @return The value to which this map maps the specified key. * @throws NullPointerException if the key is {@code null}. */ @Override public synchronized V get(final Object key) { assert WeakCollectionCleaner.DEFAULT.isAlive(); assert valid() : count; final int index = (key.hashCode() & 0x7FFFFFFF) % table.length; for (Entry e=table[index]; e!=null; e=e.next) { if (key.equals(e.key)) { return e.get(); } } return null; }
/** * Stops the cleaner thread. Calling this method is recommended in all long running applications * with custom class loaders (e.g., web applications). */ public void exit() { // try to stop it gracefully synchronized (this) { referenceQueue = null; } this.interrupt(); try { this.join(500); } catch (InterruptedException e) { } // last resort tentative to kill the cleaner thread if (this.isAlive()) this.stop(); } }
assert WeakCollectionCleaner.DEFAULT.isAlive(); assert valid() : count; if (obj != null) {
/** * Implementation of {@link #put} and {@link #remove} operations. */ private synchronized V intern(final K key, final V value) { assert WeakCollectionCleaner.DEFAULT.isAlive(); assert valid() : count; /* * Check if {@code obj} is already contained in this * {@code WeakValueHashMap}. If yes, clear it. */ V oldValue = null; final int hash = key.hashCode() & 0x7FFFFFFF; int index = hash % table.length; for (Entry e=table[index]; e!=null; e=e.next) { if (key.equals(e.key)) { oldValue = e.get(); e.clear(); } } if (value != null) { if (count >= threshold) { rehash(true); index = hash % table.length; } table[index] = new Entry(key, value, table[index], index); count++; } assert valid(); return oldValue; }
/** * Implementation of {@link #put} and {@link #remove} operations. */ private synchronized Object intern(final Object key, final Object value) { assert WeakCollectionCleaner.DEFAULT.isAlive(); assert valid() : count; /* * Check if {@code obj} is already contained in this * {@code WeakValueHashMap}. If yes, clear it. */ Object oldValue = null; final int hash = key.hashCode() & 0x7FFFFFFF; int index = hash % table.length; for (Entry e=table[index]; e!=null; e=e.next) { if (key.equals(e.key)) { oldValue = e.get(); e.clear(); } } if (value != null) { if (count >= threshold) { rehash(true); index = hash % table.length; } table[index] = new Entry(key, value, table[index], index); count++; } assert valid(); return oldValue; }
assert WeakCollectionCleaner.DEFAULT.isAlive(); assert valid() : count; if (obj != null) {