public Map makeEmptyMap() { ReferenceMap map = new ReferenceMap(ReferenceMap.WEAK, ReferenceMap.WEAK); return map; }
public void clear() { ReferenceMap.this.clear(); }
/** * Reads the contents of this object from the given input stream. * * @param inp the input stream to read from * @throws IOException if the stream raises it * @throws ClassNotFoundException if the stream raises it */ private void readObject(ObjectInputStream inp) throws IOException, ClassNotFoundException { inp.defaultReadObject(); table = new Entry[inp.readInt()]; threshold = (int)(table.length * loadFactor); queue = new ReferenceQueue(); Object key = inp.readObject(); while (key != null) { Object value = inp.readObject(); put(key, value); key = inp.readObject(); } }
/** * Removes the key and its associated value from this map. * * @param key the key to remove * @return the value associated with that key, or null if * the key was not in the map */ public Object remove(Object key) { if (key == null) return null; purge(); int hash = key.hashCode(); int index = indexFor(hash); Entry previous = null; Entry entry = table[index]; while (entry != null) { if ((hash == entry.hash) && key.equals(entry.getKey())) { if (previous == null) table[index] = entry.next; else previous.next = entry.next; this.size--; modCount++; return entry.getValue(); } previous = entry; entry = entry.next; } return null; }
if (value == null) throw new NullPointerException("null values not allowed"); purge(); if (size + 1 > threshold) resize(); int index = indexFor(hash); Entry entry = table[index]; while (entry != null) { key = toReference(keyType, key, hash); value = toReference(valueType, value, hash); table[index] = new Entry(key, hash, value, table[index]); return null;
protected Map getContextInstanceCache() { Object contextKey = getContextKey(); Map contextCache = (Map) cache.get(contextKey); if (contextCache == null) { contextCache = new ReferenceMap(); cache.put(contextKey, contextCache); } return contextCache; }
public boolean remove(Object o) { Object r = ReferenceMap.this.remove(o); return r != null; }
public EntryIterator() { index = (size() != 0 ? table.length : 0); // have to do this here! size() invocation above // may have altered the modCount. expectedModCount = modCount; }
/** * inernal, clear cache */ private void clearCache() { if(this.cache == null) { this.cache = new ReferenceMap(); } else { this.cache.clear(); } }
protected final void setLastObject(JRVirtualizable o) { if (lastObject != o) { if (o != null) { JRVirtualizationContext context = o.getContext(); Object ownerLast = lastObjectMap.get(context); if (ownerLast != o) { if (ownerLast != null) { lastObjectSet.remove(ownerLast); } lastObjectMap.put(context, o); lastObjectSet.put(o, Boolean.TRUE); } } this.lastObject = o; } }
public boolean contains(Object o) { return containsKey(o); }
protected String[] getExtensionBeanNames(Class extensionType) { synchronized (extensionBeanNamesCache) { String[] beanNames = (String[]) extensionBeanNamesCache.get(extensionType); if (beanNames == null) { beanNames = findExtensionBeanNames(extensionType); extensionBeanNamesCache.put(extensionType, beanNames); } return beanNames; } }
/** * Resizes this hash table by doubling its capacity. * This is an expensive operation, as entries must * be copied from the old smaller table to the new * bigger table. */ private void resize() { Entry[] old = table; table = new Entry[old.length * 2]; for (int i = 0; i < old.length; i++) { Entry next = old[i]; while (next != null) { Entry entry = next; next = next.next; int index = indexFor(entry.hash); entry.next = table[index]; table[index] = entry; } old[i] = null; } threshold = (int)(table.length * loadFactor); }
/** * Writes this object to the given output stream. * * @param out the output stream to write to * @throws IOException if the stream raises it */ private void writeObject(ObjectOutputStream out) throws IOException { out.defaultWriteObject(); out.writeInt(table.length); // Have to use null-terminated list because size might shrink // during iteration for (Iterator iter = entrySet().iterator(); iter.hasNext();) { Map.Entry entry = (Map.Entry)iter.next(); out.writeObject(entry.getKey()); out.writeObject(entry.getValue()); } out.writeObject(null); }
/** * Returns the size of this map. * * @return the size of this map */ public int size() { purge(); return size; }
if (value == null) throw new NullPointerException("null values not allowed"); purge(); if (size + 1 > threshold) resize(); int index = indexFor(hash); Entry entry = table[index]; while (entry != null) { key = toReference(keyType, key, hash); value = toReference(valueType, value, hash); table[index] = new Entry(key, hash, value, table[index]); return null;
public boolean remove(Object o) { Object r = ReferenceMap.this.remove(o); return r != null; }
public int size() { return ReferenceMap.this.size(); }