001    /**
002     * Copyright (c) 2000-2013 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.util;
016    
017    import java.io.Serializable;
018    
019    /**
020     * @author Brian Wing Shun Chan
021     */
022    public class ObjectValuePair<K, V> implements Serializable {
023    
024            public ObjectValuePair() {
025            }
026    
027            public ObjectValuePair(K key, V value) {
028                    _key = key;
029                    _value = value;
030            }
031    
032            @Override
033            public boolean equals(Object obj) {
034                    if (this == obj) {
035                            return true;
036                    }
037    
038                    if (!(obj instanceof ObjectValuePair<?, ?>)) {
039                            return false;
040                    }
041    
042                    ObjectValuePair<K, V> kvp = (ObjectValuePair<K, V>)obj;
043    
044                    if (Validator.equals(_key, kvp._key)) {
045                            return true;
046                    }
047    
048                    return false;
049            }
050    
051            public K getKey() {
052                    return _key;
053            }
054    
055            public V getValue() {
056                    return _value;
057            }
058    
059            @Override
060            public int hashCode() {
061                    if (_key != null) {
062                            return _key.hashCode();
063                    }
064                    else {
065                            return 0;
066                    }
067            }
068    
069            public void setKey(K key) {
070                    _key = key;
071            }
072    
073            public void setValue(V value) {
074                    _value = value;
075            }
076    
077            private static final long serialVersionUID = 6341296770402285296L;
078    
079            private K _key;
080            private V _value;
081    
082    }