1 19 package org.netbeans.mdr.persistence.btreeimpl.btreestorage; 20 21 import java.lang.ref.*; 22 23 import org.netbeans.mdr.persistence.*; 24 25 28 class CacheReference extends WeakReference { 31 32 33 private Object key; 34 35 private Object hardRef; 36 37 38 40 45 CacheReference(Object m, Object o, ReferenceQueue q) { 46 super(o, q); 47 key = m; 48 } 49 50 51 public String toString() { 52 return key.toString(); 53 } 54 55 56 public int hashCode() { 57 return key.hashCode(); 58 } 59 60 61 public boolean equals(Object o) { 62 if (!(o instanceof CacheReference)) 63 return false; 64 65 CacheReference cr = (CacheReference)o; 66 return cr.key.equals(key); 67 } 68 69 71 public void harden() { 72 hardRef = get(); 73 } 74 75 77 public void weaken() { 78 hardRef = null; 79 } 80 81 83 public boolean isHard() { 84 return hardRef != null; 85 } 86 87 88 90 public void clear() { 91 weaken(); 92 key = null; 93 super.clear(); 94 } 95 96 97 98 Object getKey() { 99 return key; 100 } 101 102 } 103 | Popular Tags |