/** * Removes all mappings from this map. */ public void clear() { processQueue(); hash.clear(); } }
/** * Returns a set of the mappings contained in this hash table. */ public Set entrySet() { processQueue(); return hash.entrySet(); }
/** * Returns the number of key-value mappings in this map. <strong>Note:</strong> * <em>In contrast with most implementations of the * <code>Map</code> interface, the time required by this operation is * linear in the size of the map.</em> */ public int size() { processQueue(); return hash.size(); }
/** * Returns <code>true</code> if this map contains no key-value mappings. */ public boolean isEmpty() { processQueue(); return hash.isEmpty(); }
/** * Returns <code>true</code> if this map contains a mapping for the * specified key. * * @param key * The key whose presence in this map is to be tested. */ public boolean containsKey(Object key) { processQueue(); return hash.containsKey(key); }
/** * Removes the mapping for the given <code>key</code> from this map, if * present. * * @param key * The key whose mapping is to be removed. * * @return The value to which this key was mapped, or <code>null</code> if * there was no mapping for the key. */ public Object remove(Object key) { processQueue(); return hash.remove(key); }
/** * Returns the value to which this map maps the specified <code>key</code>. * If this map does not contain a value for this key, then return * <code>null</code>. * * @param key * The key whose associated value, if any, is to be returned. */ public Object get(Object key) { processQueue(); SoftReference ref = (SoftReference)hash.get(key); if (ref != null) return ref.get(); return null; }
/** * Returns <code>true</code> if this map contains no key-value mappings. */ @Override public boolean isEmpty() { processQueue(); return hash.isEmpty(); }
/** * Returns <code>true</code> if this map contains a mapping for the * specified key. * * @param key * The key whose presence in this map is to be tested. */ @Override public boolean containsKey(Object key) { processQueue(); return hash.containsKey(key); }
/** * Returns the number of key-value mappings in this map. <strong>Note:</strong> * <em>In contrast with most implementations of the * <code>Map</code> interface, the time required by this operation is * linear in the size of the map.</em> */ @Override public int size() { processQueue(); return hash.size(); }
/** * Removes all mappings from this map. */ @Override public void clear() { processQueue(); hash.clear(); }
@Override public Set<K> keySet() { processQueue(); return hash.keySet(); }
/** * Updates this map so that the given <code>key</code> maps to the given * <code>value</code>. If the map previously contained a mapping for * <code>key</code> then that mapping is replaced and the previous value * is returned. * * @param key * The key that is to be mapped to the given <code>value</code> * @param value * The value to which the given <code>key</code> is to be * mapped * * @return The previous value to which this key was mapped, or * <code>null</code> if if there was no mapping for the key */ public Object put(Object key, Object value) { processQueue(); Object rtn = hash.put(key, SoftValueRef.create(key, value, queue)); if (rtn != null) rtn = ((SoftReference)rtn).get(); return rtn; }
@Override public Collection<V> values() { processQueue(); List<V> ret = new ArrayList<V>(); for (SoftValueRef<K,V> e:hash.values()) ret.add(e.get()); return ret; }
/** * Returns a set of the mappings contained in this hash table. */ @Override public Set<Map.Entry<K, V>> entrySet() { processQueue(); Set<Entry<K,V>> ret = new HashSet<Entry<K,V>>(); for (Entry<K,SoftValueRef<K,V>> e:hash.entrySet()) ret.add(new SimpleImmutableEntry<K,V> ( e.getKey(), e.getValue().get())); return ret; }
@Override public void putAll(Map<? extends K,? extends V> arg0) { processQueue(); for (K key:arg0.keySet()) put(key, arg0.get(key)); }
@Override public boolean containsValue(Object arg0) { processQueue(); if (null == arg0) return false; for (SoftValueRef<K,V> e:hash.values()) if (null != e && arg0.equals(e.get())) return true; return false; }
/** * Returns the value to which this map maps the specified <code>key</code>. * If this map does not contain a value for this key, then return * <code>null</code>. * * @param key * The key whose associated value, if any, is to be returned. */ @Override public V get(Object key) { processQueue(); return valueOrNull(hash.get(key)); }
/** * Removes the mapping for the given <code>key</code> from this map, if * present. * * @param key * The key whose mapping is to be removed. * * @return The value to which this key was mapped, or <code>null</code> if * there was no mapping for the key. */ @Override public V remove(Object key) { processQueue(); return valueOrNull(hash.remove(key)); }
/** * Updates this map so that the given <code>key</code> maps to the given * <code>value</code>. If the map previously contained a mapping for * <code>key</code> then that mapping is replaced and the previous value * is returned. * * @param key * The key that is to be mapped to the given <code>value</code> * @param value * The value to which the given <code>key</code> is to be * mapped * * @return The previous value to which this key was mapped, or * <code>null</code> if if there was no mapping for the key */ @Override public V put(K key, V value) { processQueue(); return valueOrNull(hash.put(key, SoftValueRef.create(key, value, queue))); }