| EqualityWeakReference.java |
1 /**
2 * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3 *
4 * The contents of this file are subject to the terms of the Liferay Enterprise
5 * Subscription License ("License"). You may not use this file except in
6 * compliance with the License. You can obtain a copy of the License by
7 * contacting Liferay, Inc. See the License for the specific language governing
8 * permissions and limitations under the License, including but not limited to
9 * distribution rights of the Software.
10 *
11 *
12 *
13 */
14
15 package com.liferay.portal.kernel.memory;
16
17 import com.liferay.portal.kernel.util.Validator;
18
19 import java.lang.ref.ReferenceQueue;
20 import java.lang.ref.WeakReference;
21
22 /**
23 * <a href="EqualityWeakReference.java.html"><b><i>View Source</i></b></a>
24 *
25 * @author Shuyang Zhou
26 */
27 public class EqualityWeakReference<T> extends WeakReference<T> {
28
29 public EqualityWeakReference(T referent) {
30 super(referent);
31
32 _hashCode = referent.hashCode();
33 }
34
35 public EqualityWeakReference(
36 T referent, ReferenceQueue<? super T> referenceQueue) {
37
38 super(referent, referenceQueue);
39
40 _hashCode = referent.hashCode();
41 }
42
43 public boolean equals(Object obj) {
44 if (this == obj) {
45 return true;
46 }
47
48 if (!(obj instanceof EqualityWeakReference<?>)) {
49 return false;
50 }
51
52 EqualityWeakReference<?> equalityWeakReference =
53 (EqualityWeakReference<?>)obj;
54
55 if (Validator.equals(get(), equalityWeakReference.get())) {
56 return true;
57 }
58
59 return false;
60 }
61
62 public int hashCode() {
63 return _hashCode;
64 }
65
66 private final int _hashCode;
67
68 }