1 22 23 24 package com.mchange.v1.identicator; 25 26 import java.lang.ref.*; 27 28 30 final class WeakIdHashKey extends IdHashKey 31 { 32 Ref keyRef; 33 int hash; 34 35 public WeakIdHashKey(Object keyObj, Identicator id, ReferenceQueue rq) 36 { 37 super( id ); 38 39 if (keyObj == null) 40 throw new UnsupportedOperationException ("Collection does not accept nulls!"); 41 42 this.keyRef = new Ref( keyObj, rq ); 43 this.hash = id.hash( keyObj ); 44 } 45 46 public Ref getInternalRef() 47 { return this.keyRef; } 48 49 public Object getKeyObj() 50 { return keyRef.get(); } 51 52 public boolean equals(Object o) 53 { 54 if (o instanceof WeakIdHashKey) 56 { 57 WeakIdHashKey other = (WeakIdHashKey) o; 58 if (this.keyRef == other.keyRef) 59 return true; 60 else 61 { 62 Object myKeyObj = this.keyRef.get(); 63 Object oKeyObj = other.keyRef.get(); 64 if (myKeyObj == null || oKeyObj == null) 65 return false; 66 else 67 return id.identical( myKeyObj, oKeyObj ); 68 } 69 } 70 else 71 return false; 72 } 73 74 public int hashCode() 75 { return hash; } 76 77 class Ref extends WeakReference 78 { 79 public Ref( Object referant, ReferenceQueue rq ) 80 { super( referant, rq ); } 81 82 WeakIdHashKey getKey() 83 { return WeakIdHashKey.this; } 84 } 85 } 86 | Popular Tags |