1    /*
2    Copyright 2002 by Ralph Hartley
3    This software is licenced under the terms of the
4    Gnu Public Licence
5    */
6    
7    import java.lang.ref.*;
8    
9    public class TransparentSoftReference extends SoftReference implements Comparable {
10   
11     int hash;
12   
13     public TransparentSoftReference(Object target) {
14       super(target);
15       hash = target.hashCode();
16     }
17   
18     public int hashCode() {
19       return(hash);
20     }
21   
22     public boolean equals(Object that) {
23       if (hash!=that.hashCode()) return(false);
24       return(compareTo(that)==0);
25     }
26   
27     public int compareTo(Object that) {
28       if (that==this) return(0);
29       if (that==null) return(-1);
30       Object target = get();
31       if (that instanceof SoftReference)
32         that = ((SoftReference)that).get();
33       if (target==that) return(0);
34       if (target==null) return(1);
35       if (target instanceof Comparable)
36         return(((Comparable)target).compareTo(that));
37       return(-1);
38     }
39   }
40