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