| ReadWriteLockKey.java |
1 /**
2 * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3 *
4 * This library is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License as published by the Free
6 * Software Foundation; either version 2.1 of the License, or (at your option)
7 * any later version.
8 *
9 * This library is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12 * details.
13 */
14
15 package com.liferay.portal.kernel.concurrent;
16
17 import com.liferay.portal.kernel.util.Validator;
18
19 /**
20 * <a href="ReadWriteLockKey.java.html"><b><i>View Source</i></b></a>
21 *
22 * <p>
23 * Represents a key that is used by ReadWriteLockRegistry. T must also be
24 * immutable and properly implement the equals and hashCode methods.
25 * </p>
26 *
27 * @author Shuyang Zhou
28 * @see ReadWriteLockRegistry
29 */
30 public class ReadWriteLockKey<T> {
31
32 public ReadWriteLockKey(T key, boolean writeLock) {
33 _key = key;
34 _writeLock = writeLock;
35 }
36
37 public boolean equals(Object obj) {
38 if (obj == null) {
39 return false;
40 }
41
42 if (!(obj instanceof ReadWriteLockKey<?>)) {
43 return false;
44 }
45
46 ReadWriteLockKey<T> readWriteLockKey = (ReadWriteLockKey<T>)obj;
47
48 if (Validator.equals(_key, readWriteLockKey._key)) {
49 return true;
50 }
51
52 return false;
53 }
54
55 public T getKey() {
56 return _key;
57 }
58
59 public int hashCode() {
60 return _key.hashCode();
61 }
62
63 public boolean isWriteLock() {
64 return _writeLock;
65 }
66
67 private final T _key;
68 private final boolean _writeLock;
69
70 }