public V get(Object key) { processQueue(); V result = null; SoftValue<V, K> value = map.get(key); if (value != null) { //unwrap the 'real' value from the SoftReference result = value.get(); if (result == null) { //The wrapped value was garbage collected, so remove this entry from the backing map: //noinspection SuspiciousMethodCalls map.remove(key); } else { //Add this value to the beginning of the strong reference queue (FIFO). addToStrongReferences(result); } } return result; }
/** * Creates a new entry, but wraps the value in a SoftValue instance to enable auto garbage collection. */ public V put(K key, V value) { processQueue(); // throw out garbage collected values first SoftValue<V, K> sv = new SoftValue<V, K>(value, key, queue); SoftValue<V, K> previous = map.put(key, sv); addToStrongReferences(value); return previous != null ? previous.get() : null; }
public V get(Object key) { processQueue(); V result = null; SoftValue<V, K> value = map.get(key); if (value != null) { //unwrap the 'real' value from the SoftReference result = value.get(); if (result == null) { //The wrapped value was garbage collected, so remove this entry from the backing map: //noinspection SuspiciousMethodCalls map.remove(key); } else { //Add this value to the beginning of the strong reference queue (FIFO). addToStrongReferences(result); } } return result; }
public V get(Object key) { processQueue(); V result = null; SoftValue<V, K> value = map.get(key); if (value != null) { //unwrap the 'real' value from the SoftReference result = value.get(); if (result == null) { //The wrapped value was garbage collected, so remove this entry from the backing map: //noinspection SuspiciousMethodCalls map.remove(key); } else { //Add this value to the beginning of the strong reference queue (FIFO). addToStrongReferences(result); } } return result; }
/** * Creates a new entry, but wraps the value in a SoftValue instance to enable auto garbage collection. */ public V put(K key, V value) { processQueue(); // throw out garbage collected values first SoftValue<V, K> sv = new SoftValue<V, K>(value, key, queue); SoftValue<V, K> previous = map.put(key, sv); addToStrongReferences(value); return previous != null ? previous.get() : null; }
/** * Creates a new entry, but wraps the value in a SoftValue instance to enable auto garbage collection. */ public V put(K key, V value) { processQueue(); // throw out garbage collected values first SoftValue<V, K> sv = new SoftValue<V, K>(value, key, queue); SoftValue<V, K> previous = map.put(key, sv); addToStrongReferences(value); return previous != null ? previous.get() : null; }