01: /*
02: Copyright (C) 2007 Mobixess Inc. http://www.java-objects-database.com
03:
04: This file is part of the JODB (Java Objects Database) open source project.
05:
06: JODB is free software; you can redistribute it and/or modify it under
07: the terms of version 2 of the GNU General Public License as published
08: by the Free Software Foundation.
09:
10: JODB is distributed in the hope that it will be useful, but WITHOUT ANY
11: WARRANTY; without even the implied warranty of MERCHANTABILITY or
12: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13: for more details.
14:
15: You should have received a copy of the GNU General Public License along
16: with this program; if not, write to the Free Software Foundation, Inc.,
17: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18: */
19: package com.mobixess.jodb.core.transaction;
20:
21: import java.lang.ref.ReferenceQueue;
22: import java.lang.ref.WeakReference;
23:
24: public class ActiveObjectWeakRefHolder extends WeakReference<Object> {
25:
26: protected int _identityHashCode;
27:
28: public ActiveObjectWeakRefHolder(Object referent) {
29: super (referent);
30: _identityHashCode = System.identityHashCode(referent);
31: }
32:
33: /**
34: * @param referent
35: * @param q
36: */
37: public ActiveObjectWeakRefHolder(Object referent,
38: ReferenceQueue<? super Object> q) {
39: super (referent, q);
40: _identityHashCode = System.identityHashCode(referent);
41: }
42:
43: protected Object getReferencedObject() {
44: return get();
45: }
46:
47: @Override
48: public int hashCode() {
49: return _identityHashCode;
50: }
51:
52: @Override
53: public boolean equals(Object obj) {
54: if (obj == this ) {
55: return true;
56: }
57: if (obj == null || !(obj instanceof ActiveObjectWeakRefHolder)) {
58: return false;
59: }
60: ActiveObjectWeakRefHolder o1 = (ActiveObjectWeakRefHolder) obj;
61: Object o1Referent = o1.getReferencedObject();
62: Object currentReferent = getReferencedObject();
63: return o1Referent == currentReferent;
64: }
65:
66: @Override
67: public String toString() {
68: return this .getClass().getSimpleName() + " "
69: + Integer.toHexString(_identityHashCode);
70: }
71:
72: }
|