/** Here we put the key, value pair into the HashMap using a SoftValue object. */
 @Override
 public V put(final K aKey, final V aValue) {
   // throw out garbage collected values first
   _processQueue();
   final SoftValue<K, V> aOld = m_aSrcMap.put(aKey, new SoftValue<K, V>(aKey, aValue, m_aQueue));
   return aOld == null ? null : aOld.get();
 }
 @Override
 public V remove(final Object aKey) {
   // throw out garbage collected values first
   _processQueue();
   final SoftValue<K, V> aRemoved = m_aSrcMap.remove(aKey);
   return aRemoved == null ? null : aRemoved.get();
 }
 @SuppressWarnings("unchecked")
 @Override
 public V get(final Object aKey) {
   V ret = null;
   // We get the SoftReference represented by that key
   final SoftValue<K, V> aSoftValue = m_aSrcMap.get(aKey);
   if (aSoftValue != null) {
     // From the SoftReference we get the value, which can be
     // null if it was not in the map, or it was removed in
     // the processQueue() method defined below
     ret = aSoftValue.get();
     if (ret == null) {
       // If the value has been garbage collected, remove the
       // entry from the HashMap.
       if (m_aSrcMap.remove(aKey) != null) onEntryRemoved((K) aKey);
     }
   }
   return ret;
 }
Example #4
0
 /**
  * Store the object. The return value of this method is null or a SoftReference.
  *
  * @param key the key
  * @param value the value
  * @return null or the old object.
  */
 public V put(K key, V value) {
   processQueue();
   SoftValue<V> old = map.put(key, new SoftValue<V>(value, queue, key));
   return old == null ? null : old.get();
 }