114997bc5c49c562a6d7d8e3328f6f5bb85b9ef3
[IRC.git] / Robust / Transactions / jcarderdstm2version / src / com / enea / jcarder / common / Lock.java
1 /*
2  * JCarder -- cards Java programs to keep threads disentangled
3  *
4  * Copyright (C) 2006-2007 Enea AB
5  * Copyright (C) 2007 Ulrik Svensson
6  * Copyright (C) 2007 Joel Rosdahl
7  *
8  * This program is made available under the GNU GPL version 2, with a special
9  * exception for linking with JUnit. See the accompanying file LICENSE.txt for
10  * details.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE.
15  */
16
17 package com.enea.jcarder.common;
18
19 //import net.jcip.annotations.ThreadSafe;
20
21 /**
22  * A Lock instance represents a Java monitor object.
23  */
24 //@ThreadSafe
25 public final class Lock {
26     private final String mClassName;
27     private final int mObjectId;
28
29     public Lock(Object lock) {
30         mClassName = lock.getClass().getName();
31         mObjectId = System.identityHashCode(lock);
32     }
33
34     public Lock(String className, int objectId) {
35         mClassName = className;
36         mObjectId = objectId;
37     }
38
39     public String toString() {
40         return mClassName + '@' + Integer.toHexString(mObjectId).toUpperCase();
41     }
42
43     public int getObjectId() {
44         return mObjectId;
45     }
46
47     public String getClassName() {
48         return mClassName;
49     }
50
51     public int hashCode() {
52         return mObjectId;
53     }
54
55     public boolean equals(Object obj) {
56         if (this == obj) {
57             return true;
58         }
59         if (obj == null) {
60             return false;
61         }
62         if (getClass() != obj.getClass()) {
63             return false;
64         }
65         final Lock other = (Lock) obj;
66         return mObjectId == other.mObjectId
67                && mClassName.equals(other.mClassName);
68     }
69 }