1 22 package org.jboss.util; 23 24 import java.lang.ref.SoftReference ; 25 import java.lang.ref.ReferenceQueue ; 26 27 35 public final class SoftObject 36 extends SoftReference 37 { 38 39 protected final int hashCode; 40 41 46 public SoftObject(final Object obj) { 47 super(obj); 48 hashCode = obj.hashCode(); 49 } 50 51 57 public SoftObject(final Object obj, final ReferenceQueue queue) { 58 super(obj, queue); 59 hashCode = obj.hashCode(); 60 } 61 62 68 public boolean equals(final Object obj) { 69 if (obj == this) return true; 70 71 if (obj != null && obj.getClass() == getClass()) { 72 SoftObject soft = (SoftObject)obj; 73 74 Object a = this.get(); 75 Object b = soft.get(); 76 if (a == null || b == null) return false; 77 if (a == b) return true; 78 79 return a.equals(b); 80 } 81 82 return false; 83 } 84 85 90 public int hashCode() { 91 return hashCode; 92 } 93 94 95 99 105 public static SoftObject create(final Object obj) { 106 if (obj == null) return null; 107 else return new SoftObject(obj); 108 } 109 110 117 public static SoftObject create(final Object obj, 118 final ReferenceQueue queue) 119 { 120 if (obj == null) return null; 121 else return new SoftObject(obj, queue); 122 } 123 } 124 | Popular Tags |