comparison src/goodjava/util/SoftCacheMap.java @ 1498:1b809d2fdf03

add CacheMap
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 08 May 2020 18:07:14 -0600
parents
children
comparison
equal deleted inserted replaced
1497:f04bfbb08721 1498:1b809d2fdf03
1 package goodjava.util;
2
3 import java.lang.ref.ReferenceQueue;
4 import java.lang.ref.SoftReference;
5
6
7 public final class SoftCacheMap<K,V> extends CacheMap<K,V> {
8
9 static final class MySoftReference<K,V> extends SoftReference<V> implements MyReference<K,V> {
10 private final K key;
11
12 MySoftReference(K key,V value,ReferenceQueue<V> q) {
13 super(value,q);
14 this.key = key;
15 }
16
17 public K key() {
18 return key;
19 }
20
21 public boolean equals(Object obj) {
22 Object o = this.get();
23 if( o==null )
24 return false;
25 SoftReference ref = (SoftReference)obj;
26 return o.equals(ref.get());
27 }
28
29 }
30
31 protected MyReference<K,V> newReference(K key,V value,ReferenceQueue<V> q) {
32 return new MySoftReference<K,V>(key,value,q);
33 }
34
35 }