001    /**
002     * Copyright (c) 2000-2011 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            @Override
036            public boolean equals(Object obj) {
037                    if (obj == null) {
038                            return false;
039                    }
040    
041                    if (!(obj instanceof ReadWriteLockKey<?>)) {
042                            return false;
043                    }
044    
045                    ReadWriteLockKey<T> readWriteLockKey = (ReadWriteLockKey<T>)obj;
046    
047                    if (Validator.equals(_key, readWriteLockKey._key)) {
048                            return true;
049                    }
050    
051                    return false;
052            }
053    
054            public T getKey() {
055                    return _key;
056            }
057    
058            @Override
059            public int hashCode() {
060                    return _key.hashCode();
061            }
062    
063            public boolean isWriteLock() {
064                    return _writeLock;
065            }
066    
067            private final T _key;
068            private final boolean _writeLock;
069    
070    }