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