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