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   * <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  }