2 * JCarder -- cards Java programs to keep threads disentangled
4 * Copyright (C) 2006-2007 Enea AB
5 * Copyright (C) 2007 Ulrik Svensson
6 * Copyright (C) 2007 Joel Rosdahl
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
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.
17 package com.enea.jcarder.common;
19 //import net.jcip.annotations.ThreadSafe;
22 * A Lock instance represents a Java monitor object.
25 public final class Lock {
26 private final String mClassName;
27 private final int mObjectId;
29 public Lock(Object lock) {
30 mClassName = lock.getClass().getName();
31 mObjectId = System.identityHashCode(lock);
34 public Lock(String className, int objectId) {
35 mClassName = className;
39 public String toString() {
40 return mClassName + '@' + Integer.toHexString(mObjectId).toUpperCase();
43 public int getObjectId() {
47 public String getClassName() {
51 public int hashCode() {
55 public boolean equals(Object obj) {
62 if (getClass() != obj.getClass()) {
65 final Lock other = (Lock) obj;
66 return mObjectId == other.mObjectId
67 && mClassName.equals(other.mClassName);