annotate src/goodjava/util/SoftCacheMap.java @ 1625:57c8baadb357

handle UnsupportedClassVersionError
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 05 Sep 2021 12:32:27 -0600
parents 1b809d2fdf03
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1498
1b809d2fdf03 add CacheMap
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 package goodjava.util;
1b809d2fdf03 add CacheMap
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2
1b809d2fdf03 add CacheMap
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 import java.lang.ref.ReferenceQueue;
1b809d2fdf03 add CacheMap
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 import java.lang.ref.SoftReference;
1b809d2fdf03 add CacheMap
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5
1b809d2fdf03 add CacheMap
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6
1b809d2fdf03 add CacheMap
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 public final class SoftCacheMap<K,V> extends CacheMap<K,V> {
1b809d2fdf03 add CacheMap
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8
1b809d2fdf03 add CacheMap
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 static final class MySoftReference<K,V> extends SoftReference<V> implements MyReference<K,V> {
1b809d2fdf03 add CacheMap
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 private final K key;
1b809d2fdf03 add CacheMap
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11
1b809d2fdf03 add CacheMap
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 MySoftReference(K key,V value,ReferenceQueue<V> q) {
1b809d2fdf03 add CacheMap
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 super(value,q);
1b809d2fdf03 add CacheMap
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 this.key = key;
1b809d2fdf03 add CacheMap
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 }
1b809d2fdf03 add CacheMap
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16
1b809d2fdf03 add CacheMap
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 public K key() {
1b809d2fdf03 add CacheMap
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18 return key;
1b809d2fdf03 add CacheMap
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 }
1b809d2fdf03 add CacheMap
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20
1b809d2fdf03 add CacheMap
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 public boolean equals(Object obj) {
1b809d2fdf03 add CacheMap
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 Object o = this.get();
1b809d2fdf03 add CacheMap
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 if( o==null )
1b809d2fdf03 add CacheMap
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 return false;
1b809d2fdf03 add CacheMap
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 SoftReference ref = (SoftReference)obj;
1b809d2fdf03 add CacheMap
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 return o.equals(ref.get());
1b809d2fdf03 add CacheMap
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 }
1b809d2fdf03 add CacheMap
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28
1b809d2fdf03 add CacheMap
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 }
1b809d2fdf03 add CacheMap
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30
1b809d2fdf03 add CacheMap
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 protected MyReference<K,V> newReference(K key,V value,ReferenceQueue<V> q) {
1b809d2fdf03 add CacheMap
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 return new MySoftReference<K,V>(key,value,q);
1b809d2fdf03 add CacheMap
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 }
1b809d2fdf03 add CacheMap
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34
1b809d2fdf03 add CacheMap
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 }