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.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   * Represents a key that is used by ReadWriteLockRegistry. T must also be
23   * immutable and properly implement the equals and hashCode methods. <a
24   * href="ReadWriteLockKey.java.html"><b><i>View Source</i></b></a>
25   *
26   * @author Shuyang Zhou
27   * @see    ReadWriteLockRegistry
28   */
29  public class ReadWriteLockKey<T> {
30  
31      public ReadWriteLockKey(T key, boolean writeLock) {
32          _key = key;
33          _writeLock = writeLock;
34      }
35  
36      public boolean equals(Object obj) {
37          if (obj == null) {
38              return false;
39          }
40  
41          if (!(obj instanceof ReadWriteLockKey<?>)) {
42              return false;
43          }
44  
45          ReadWriteLockKey<T> readWriteLockKey = (ReadWriteLockKey<T>)obj;
46  
47          if (Validator.equals(_key, readWriteLockKey._key)) {
48              return true;
49          }
50  
51          return true;
52      }
53  
54      public T getKey() {
55          return _key;
56      }
57  
58      public int hashCode() {
59          return _key.hashCode();
60      }
61  
62      public boolean isWriteLock() {
63          return _writeLock;
64      }
65  
66      private final T _key;
67      private final boolean _writeLock;
68  
69  }