001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.kernel.concurrent;
016    
017    import com.liferay.portal.kernel.util.Validator;
018    
019    /**
020     * <p>
021     * Represents a key that is used by ReadWriteLockRegistry. T must also be
022     * immutable and properly implement the equals and hashCode methods.
023     * </p>
024     *
025     * @author Shuyang Zhou
026     * @see    ReadWriteLockRegistry
027     */
028    public class ReadWriteLockKey<T> {
029    
030            public ReadWriteLockKey(T key, boolean writeLock) {
031                    _key = key;
032                    _writeLock = writeLock;
033            }
034    
035            public boolean equals(Object obj) {
036                    if (obj == null) {
037                            return false;
038                    }
039    
040                    if (!(obj instanceof ReadWriteLockKey<?>)) {
041                            return false;
042                    }
043    
044                    ReadWriteLockKey<T> readWriteLockKey = (ReadWriteLockKey<T>)obj;
045    
046                    if (Validator.equals(_key, readWriteLockKey._key)) {
047                            return true;
048                    }
049    
050                    return false;
051            }
052    
053            public T getKey() {
054                    return _key;
055            }
056    
057            public int hashCode() {
058                    return _key.hashCode();
059            }
060    
061            public boolean isWriteLock() {
062                    return _writeLock;
063            }
064    
065            private final T _key;
066            private final boolean _writeLock;
067    
068    }