001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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 (this == obj) {
038                            return true;
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    }